[lexical-table] Bug Fix: Attach window pointerdown handler when root element is set after register#8492
Merged
etrepum merged 2 commits intoMay 11, 2026
Conversation
…element is set after register `registerTableWindowHandlers` previously bailed out and returned a no-op cleanup when `editor.getRootElement()` was null at registration time. With the Plugin API this was fine because `useEffect` runs after the ContentEditable has mounted and called `setRootElement`. With the Extension API the extension's `register()` runs during `buildEditor`, before any root element is mounted, so the window-level pointerdown handler that drives table drag selection was never attached and drag selection silently broke. Use `editor.registerRootListener` so the pointerdown handler is attached whenever a non-null root element is present and torn down cleanly when the root element changes or the listener is disposed. Fixes facebook#8491
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Collaborator
Author
|
FWIW I also had claude scan the repo for similar bugs and it looks like this is the only one, probably got taken care of between adding extensions in general and the optional cleanup return values from registerRootListener. |
ivailop7
approved these changes
May 11, 2026
Merged
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
registerTableWindowHandlersreadseditor.getRootElement()at call time and returns a no-op cleanup when it is null. WithTablePluginthis is fine because the registration runs from auseEffect, which fires after<ContentEditable>has mounted and callededitor.setRootElement(...). WithTableExtension, the extension'sregister()runs synchronously insidebuildEditor()— before any root element is mounted — so the window-levelpointerdownlistener that drives table cell drag selection was never attached. The user sees only the browser's native cell selection, which gets clobbered after a couple of cells, producing the "drag selection stops after ~2 cells" symptom reported in the issue.This PR rewrites
registerTableWindowHandlersto useeditor.registerRootListener(...)so thepointerdownlistener is attached whenever a non-null root element is present and is torn down cleanly when the root element changes or the listener is disposed. No other call sites or behavior change forTablePlugin.A regression test in
LexicalTableExtension.test.tsbuilds an editor viabuildEditorFromExtensions(TableExtension), callssetRootElementafter registration, dispatches apointerdownon a<td>, and asserts that the attachedTableObserver.anchorCellis populated — which is only true if the window handler actually ran.Closes #8491
Test plan
Before
Running the new regression test against
main:In the Stackblitz reproduction from the issue, dragging across cells in the
TableExtensioneditor stops extending the selection after ~2 cells, while the equivalentTablePlugineditor continues selecting until pointerup.After
Full unit suite passes (3058 tests, 1 new):
Drag selection in the
TableExtensionreproduction now matchesTablePlugin: the selection extends continuously across cells until the pointer is released.