fix(ui): optimize MutationObserver in NoteEditorDialog
Only observe DOM mutations when dialog is open, preventing unnecessary observer activity when the dialog is closed. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
a8bb88e10f
commit
2a4d98772b
1 changed files with 4 additions and 2 deletions
|
|
@ -70,12 +70,14 @@ export function NoteEditorDialog({ open, onOpenChange, notebookId, note }: NoteE
|
||||||
}, [open, note, fetchedNote, reset])
|
}, [open, note, fetchedNote, reset])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!open) return
|
||||||
|
|
||||||
const observer = new MutationObserver(() => {
|
const observer = new MutationObserver(() => {
|
||||||
setIsEditorFullscreen(!!document.querySelector('.w-md-editor-fullscreen'))
|
setIsEditorFullscreen(!!document.querySelector('.w-md-editor-fullscreen'))
|
||||||
})
|
})
|
||||||
observer.observe(document.body, {subtree: true, attributes: true, attributeFilter: ['class']})
|
observer.observe(document.body, { subtree: true, attributes: true, attributeFilter: ['class'] })
|
||||||
return () => observer.disconnect()
|
return () => observer.disconnect()
|
||||||
}, [])
|
}, [open])
|
||||||
|
|
||||||
const onSubmit = async (data: CreateNoteFormData) => {
|
const onSubmit = async (data: CreateNoteFormData) => {
|
||||||
if (note) {
|
if (note) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue