Skip to content

[lexical-table] Bug Fix: Attach window pointerdown handler when root element is set after register#8492

Merged
etrepum merged 2 commits into
facebook:mainfrom
etrepum:claude/fix-table-plugin-behavior-PF8Kt
May 11, 2026
Merged

[lexical-table] Bug Fix: Attach window pointerdown handler when root element is set after register#8492
etrepum merged 2 commits into
facebook:mainfrom
etrepum:claude/fix-table-plugin-behavior-PF8Kt

Conversation

@etrepum

@etrepum etrepum commented May 10, 2026

Copy link
Copy Markdown
Collaborator

Description

registerTableWindowHandlers reads editor.getRootElement() at call time and returns a no-op cleanup when it is null. With TablePlugin this is fine because the registration runs from a useEffect, which fires after <ContentEditable> has mounted and called editor.setRootElement(...). With TableExtension, the extension's register() runs synchronously inside buildEditor() — before any root element is mounted — so the window-level pointerdown listener 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 registerTableWindowHandlers to use editor.registerRootListener(...) so the pointerdown listener 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 for TablePlugin.

A regression test in LexicalTableExtension.test.ts builds an editor via buildEditorFromExtensions(TableExtension), calls setRootElement after registration, dispatches a pointerdown on a <td>, and asserts that the attached TableObserver.anchorCell is populated — which is only true if the window handler actually ran.

Closes #8491

Test plan

Before

Running the new regression test against main:

× attaches the window pointerdown handler when setRootElement is called after register
  AssertionError: expected null not to be null
    expect(observerAfter.anchorCell).not.toBeNull();

In the Stackblitz reproduction from the issue, dragging across cells in the TableExtension editor stops extending the selection after ~2 cells, while the equivalent TablePlugin editor continues selecting until pointerup.

After

Full unit suite passes (3058 tests, 1 new):

Test Files  118 passed (118)
     Tests  3058 passed | 1 skipped (3059)

Drag selection in the TableExtension reproduction now matches TablePlugin: the selection extends continuously across cells until the pointer is released.

…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
@vercel

vercel Bot commented May 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment May 10, 2026 3:39pm
lexical-playground Ready Ready Preview, Comment May 10, 2026 3:39pm

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 10, 2026
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label May 10, 2026
@etrepum

etrepum commented May 10, 2026

Copy link
Copy Markdown
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.

@etrepum etrepum added this pull request to the merge queue May 11, 2026
Merged via the queue into facebook:main with commit fd29514 May 11, 2026
54 of 56 checks passed
@etrepum etrepum deleted the claude/fix-table-plugin-behavior-PF8Kt branch May 19, 2026 17:55
@etrepum etrepum mentioned this pull request May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: TableExtension drag selection stops after selecting two cells

3 participants