Repository navigation
[lexical-playground] Chore: Use ownerDocument and $getDocument() for shadow DOM safety - #8878
Merged
Merged
Conversation
mayrang
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
July 26, 2026 15:10
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
mayrang
force-pushed
the
chore/playground-shadow-dom-safety
branch
from
July 26, 2026 15:50
1700f9b to
35443e4
Compare
mayrang
marked this pull request as draft
July 26, 2026 16:18
mayrang
force-pushed
the
chore/playground-shadow-dom-safety
branch
from
July 27, 2026 02:11
35443e4 to
a4cd0d4
Compare
mayrang
force-pushed
the
chore/playground-shadow-dom-safety
branch
from
July 27, 2026 02:23
a4cd0d4 to
4045c68
Compare
…shadow DOM safety
mayrang
force-pushed
the
chore/playground-shadow-dom-safety
branch
from
July 27, 2026 06:57
4045c68 to
b161e88
Compare
etrepum
approved these changes
Jul 27, 2026
etrepum
left a comment
Collaborator
There was a problem hiding this comment.
This looks good, is there anything else in-progress before it's ready for final review and merge? I only noticed a small additional simplification that could be done along the way
| document.addEventListener('pointerup', handlePointerUp); | ||
| const doc = stickContainer.ownerDocument; | ||
| dragCleanupRef.current?.(); | ||
| dragCleanupRef.current = mergeRegister( |
Collaborator
There was a problem hiding this comment.
This could use registerEventListeners which would be a little more concise
| document.addEventListener('mousemove', onMouseMove, false); | ||
| document.addEventListener('mouseup', onMouseUp, false); | ||
| dragCleanupRef.current?.(); | ||
| dragCleanupRef.current = mergeRegister( |
| document.addEventListener('pointerup', handlePointerUp); | ||
| const doc = image.ownerDocument; | ||
| resizeCleanupRef.current?.(); | ||
| resizeCleanupRef.current = mergeRegister( |
Collaborator
Author
|
Thanks! I'll be back home on Thursday (KST) – will get that small tweak done and open the PR then. |
Collaborator
Author
|
Pushed — switched the three files to |
mayrang
marked this pull request as ready for review
July 30, 2026 18:27
etrepum
approved these changes
Jul 30, 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
The playground serves as reference code for developers embedding Lexical in shadow DOM or iframes, but many files used raw
documentreferences that silently break in those contexts.This PR converts all playground
document.createElement/createTextNode/createDocumentFragmentcalls to$getDocument()(35 node and plugin files), scopes event listeners toownerDocumentinstead of the globaldocument, and pointscreatePortaltargets ateditor.getRootElement()?.ownerDocument?.body. Event listener cleanup usesregisterEventListenerwith cleanup refs and double-down guards to prevent leaks during drag/resize interactions.Files intentionally left unchanged:
Modal.tsx,ExcalidrawModal.tsx,FlashMessage.tsx(app-level overlays without editor context),ImagesExtensionmodule-level constant,TestRecorderPlugin(standalone utility),ColorPicker.toHex()(canvas color utility),TweetNodeTwitter widget script injection (scripts don't execute inside shadow roots), andPagesExtension:rootCSS custom properties.Test plan
pnpm test-unit— 3996 passpnpm test-e2e-chromium— 771 pass<hr>display:)), conversion display@trigger, autocomplete select, badge display