Repository navigation
[lexical-table] Bug Fix: disconnect trackTable MutationObserver in removeListeners - #9074
Merged
Merged
Conversation
…moveListeners ## Description `TableObserver.trackTable()` creates a `MutationObserver` on the table element (`attributes` + `childList` + `subtree`), but nothing ever calls `observer.disconnect()`. `removeListeners()` aborts the DOM event listeners and undoes the command registrations, but the tracking observer outlives the `TableObserver` and the editor itself. After teardown, any mutation of the detached `<table>` subtree fires the leaked observer, whose callback calls `$getTableAndElementByKey()` and throws invariant meta#232 (`TableObserver: Expected to find TableElement in DOM for key %s`) from a MutationObserver microtask — uncatchable by `onError` or React error boundaries. It also leaks one observer plus the retained table subtree per table per editor mount. This change registers `observer.disconnect()` in `listenersToRemove`, so `removeListeners()` disconnects the tracking observer — mirroring what `resetEditor()` already does for the core mutation observer. `disconnect()` also empties the observer's record queue, which closes the race where records queued in the same task as teardown would still be delivered afterwards. No behavioral change while the editor is alive. Closes meta#9073 ## Test plan Added `packages/lexical-table/src/__tests__/unit/LexicalTableObserver.test.ts` covering both that `removeListeners()` disconnects the tracking observer and that mutations of the detached table after editor teardown no longer fire it (including records queued in the same task as teardown). ### Before `pnpm run test-unit packages/lexical-table/src/__tests__/unit/LexicalTableObserver.test.ts` (new tests against unmodified `LexicalTableObserver.ts`): ``` ❯ |unit| packages/lexical-table/src/__tests__/unit/LexicalTableObserver.test.ts (2 tests | 2 failed) 134ms × disconnects the tracking MutationObserver in removeListeners() 116ms × does not fire the tracking MutationObserver for mutations of the detached table after editor teardown 17ms FAIL |unit| ... > disconnects the tracking MutationObserver in removeListeners() AssertionError: expected +0 to be 1 // Object.is equality Test Files 1 failed (1) Tests 2 failed (2) ``` ### After `pnpm run test-unit packages/lexical-table`: ``` Test Files 13 passed (13) Tests 158 passed (158) ``` `pnpm run tsc`, `npx prettier --check` and `npx eslint` on the changed files all pass. Co-Authored-By: Claude Fable 5 <[email protected]>
kaminski-dev
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
August 19, 2026 14:33
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
approved these changes
Aug 19, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to no response for status checks
Aug 19, 2026
Merged
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
TableObserver.trackTable()creates aMutationObserveron the table element (attributes+childList+subtree), but nothing ever callsobserver.disconnect().removeListeners()aborts the DOM event listeners and undoes the command registrations, but the tracking observer outlives theTableObserverand the editor itself. After teardown, any mutation of the detached<table>subtree fires the leaked observer, whose callback calls$getTableAndElementByKey()and throws invariant #232 (TableObserver: Expected to find TableElement in DOM for key %s) from a MutationObserver microtask — uncatchable byonErroror React error boundaries. It also leaks one observer plus the retained table subtree per table per editor mount.This change registers
observer.disconnect()inlistenersToRemove, soremoveListeners()disconnects the tracking observer — mirroring whatresetEditor()already does for the core mutation observer.disconnect()also empties the observer's record queue, which closes the race where records queued in the same task as teardown would still be delivered afterwards. No behavioral change while the editor is alive.Closes #9073
Test plan
Added
packages/lexical-table/src/__tests__/unit/LexicalTableObserver.test.tscovering both thatremoveListeners()disconnects the tracking observer and that mutations of the detached table after editor teardown no longer fire it (including records queued in the same task as teardown).Before
pnpm run test-unit packages/lexical-table/src/__tests__/unit/LexicalTableObserver.test.ts(new tests against unmodifiedLexicalTableObserver.ts):After
pnpm run test-unit packages/lexical-table:pnpm run tsc,npx prettier --checkandnpx eslinton the changed files all pass.🤖 Generated with Claude Code