From 8c64f46d22a081c405ac70c8bb8644b0ce79f5ee Mon Sep 17 00:00:00 2001 From: Haneet Singh Date: Thu, 23 Jan 2025 16:03:57 -0500 Subject: [PATCH] refactor MutationObserver state initialization to resolve potential identifier conflicts --- src/useEditable.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/useEditable.ts b/src/useEditable.ts index c5ebc79..4f025b9 100644 --- a/src/useEditable.ts +++ b/src/useEditable.ts @@ -178,7 +178,7 @@ export const useEditable = ( if (!opts) opts = {}; const unblock = useState([])[1]; - const state: State = useState(() => { + const createInitialState = (): State => { const state: State = { observer: null as any, disconnected: false, @@ -190,13 +190,14 @@ export const useEditable = ( }; if (typeof MutationObserver !== 'undefined') { - state.observer = new MutationObserver(batch => { - state.queue.push(...batch); + state.observer = new MutationObserver(mutations => { + state.queue.push(...mutations); }); } return state; - })[0]; + }; + const state: State = useState(() => createInitialState())[0]; const edit = useMemo( () => ({