Skip to content

Commit

Permalink
refactor MutationObserver state initialization to resolve potential i…
Browse files Browse the repository at this point in the history
…dentifier conflicts
  • Loading branch information
Haneet Singh committed Jan 23, 2025
1 parent 008a0b5 commit 8c64f46
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/useEditable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<Edit>(
() => ({
Expand Down

0 comments on commit 8c64f46

Please sign in to comment.