Skip to content

[lexical-react] Bug Fix: Recreate decorator portals when the editor root remounts - #8921

Merged
etrepum merged 7 commits into
facebook:mainfrom
alphanull:fix/decorator-portals-on-root-remount
Aug 5, 2026
Merged

[lexical-react] Bug Fix: Recreate decorator portals when the editor root remounts#8921
etrepum merged 7 commits into
facebook:mainfrom
alphanull:fix/decorator-portals-on-root-remount

Conversation

@alphanull

Copy link
Copy Markdown
Contributor

Description

Decorator portals are created only when getElementByKey returns a host element. If decorate/listeners run while the root is detached, portals are skipped; after setRootElement attaches a new root the decorator map may be unchanged, so portals never recover.

This PR bumps a portalRev counter from registerRootListener when the root identity changes and includes it in the portal useMemo dependencies in:

  • useDecorators (legacy plugins)
  • useReactDecorators (extension / LexicalExtensionComposer)

This is timing-safe because setRootElement reconciles the DOM before firing root listeners, so getElementByKey should succeed when we recompute.

Fixes #8920

Test plan

  • Unit: UseDecoratorsRootRemount.test.tsx
    • legacy: LexicalComposer + RichTextPlugin
    • extension: LexicalExtensionComposer + RichTextExtension
  • pnpm run test-unit (4940 passed locally)
  • pnpm run ci-check (tsc / flow / prettier / lint clean locally)
  • CI green on this PR

…oot remounts

decorate() can run before setRootElement attaches the contenteditable, so
useDecorators skips createPortal when getElementByKey is still null. After
the root identity changes, recompute portals so decorator UI is not left
blank until a later remount.
… remount

Apply the same portalRev / registerRootListener fix to useReactDecorators
(LexicalExtensionComposer path) and document the intentional useMemo deps
in both hooks. Cover the extension path with a matching unit test.
@meta-cla

meta-cla Bot commented Aug 4, 2026

Copy link
Copy Markdown

Hi @alphanull!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@vercel

vercel Bot commented Aug 4, 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 Aug 5, 2026 6:25am
lexical-playground Ready Ready Preview Aug 5, 2026 6:25am

Request Review

@etrepum etrepum left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using a counter why not use the rootElement itself in the dependency array?

@meta-cla

meta-cla Bot commented Aug 4, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@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 Aug 4, 2026
…emounts

Use the editor root element identity in the portal useMemo deps instead of
a synthetic counter, per review feedback.
@alphanull

Copy link
Copy Markdown
Contributor Author

@etrepum Yeah, I think you are right, this is even better and still solves the problem. Updated the PR with the better version.

@etrepum
etrepum added this pull request to the merge queue Aug 5, 2026
Merged via the queue into facebook:main with commit 5d2dd0f Aug 5, 2026
46 checks passed
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[lexical-react] Decorator portals stay blank after editor root remount

2 participants