[lexical-react] Bug Fix: Recreate decorator portals when the editor root remounts - #8921
Conversation
…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.
|
Hi @alphanull! Thank you for your pull request and welcome to our community. Action RequiredIn 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. ProcessIn 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 If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
left a comment
There was a problem hiding this comment.
Instead of using a counter why not use the rootElement itself in the dependency array?
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
…emounts Use the editor root element identity in the portal useMemo deps instead of a synthetic counter, per review feedback.
|
@etrepum Yeah, I think you are right, this is even better and still solves the problem. Updated the PR with the better version. |
Description
Decorator portals are created only when
getElementByKeyreturns a host element. If decorate/listeners run while the root is detached, portals are skipped; aftersetRootElementattaches a new root the decorator map may be unchanged, so portals never recover.This PR bumps a
portalRevcounter fromregisterRootListenerwhen the root identity changes and includes it in the portaluseMemodependencies in:useDecorators(legacy plugins)useReactDecorators(extension /LexicalExtensionComposer)This is timing-safe because
setRootElementreconciles the DOM before firing root listeners, sogetElementByKeyshould succeed when we recompute.Fixes #8920
Test plan
UseDecoratorsRootRemount.test.tsxLexicalComposer+RichTextPluginLexicalExtensionComposer+RichTextExtensionpnpm run test-unit(4940 passed locally)pnpm run ci-check(tsc / flow / prettier / lint clean locally)