Repository navigation
Conversation
… shadow roots via platform selection APIs Make Lexical editors work when their contentEditable is inside a DOM ShadowRoot, using platform APIs only — no emulation of browser selection facilities. When a selection is inside a shadow tree the browser retargets Selection.anchorNode/focusNode/getRangeAt to the shadow host, and document.activeElement to the host, which previously prevented Lexical from resolving the selection back to its nodes. Core (lexical): - Add getDOMShadowRoots, getComposedStaticRange and getComposedSelectionPoints, which resolve selection boundary points through enclosing shadow roots with the standard Selection.getComposedRanges + Selection.direction; and getActiveElement / getActiveElementDeep, which resolve focus with (Document|ShadowRoot).activeElement. - Route the DOM->model reads (selection resolution, onSelectionChange, composition and mutation handlers) and the model->DOM write/diff in the reconciler through composed points, and resolve the active editor on selectionchange by descending shadow roots. - RangeSelection.modify keeps using native Selection.modify and reads the result via the composed StaticRange, so character/word/line navigation and deletion work inside a shadow root without re-implementing them. - The helpers degrade to the existing light-DOM reads when getComposedRanges is unavailable, so older browsers are unaffected. @lexical/clipboard: resolve the copy guard's selection through shadow roots. Playground: add a "Render in Shadow DOM" setting that portals the editor into an open shadow root, with an e2e spec covering typing, word selection, formatting and deletion. Add a dev-examples/shadow-dom project and browser unit tests, since jsdom does not implement the shadow-DOM selection APIs. https://claude.ai/code/session_01X2Aa2rteqPsVhWs4W6DW6T
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
pushed a commit
that referenced
this pull request
Sep 4, 2026
…rialization schema ## Description Six findings from review of the serialization schema, taken together because they overlap: the compact type could not describe a compact document until its children relaxed, and could not be fed back to the parser until it did. **`unionValue` rejected valid aliases (#6).** Membership is inferred from the parse for a member that declares no `accepts`, and that inference cannot see a value the member normalizes *into* its own default — it lands on the default, the input is not the default, and the member is skipped. An alias whose target is the inner default is exactly that case, so `aliasedValue` now declares `accepts` unconditionally instead of only when its inner schema does. The rule itself is now stated once, in `$schemaMatch`, which both `unionValue` and `aliasedValue` ask. **`unionValue` ran comparators on other members' values (#6).** `isEqual` asked every member (`members.some(...)`), so a custom comparator — arbitrary code written for one domain, reading fields only that domain has — was handed values it never produced, and one stray `true` reported two different values as equal, which compaction reads as "this is the default, omit it". The member is now found the way the parse finds it and has to recognize *both* values before its comparator is consulted. **`enumValue([])` was allowed (#14).** An empty domain admits nothing, so every value — including one the caller believes is in the enum — parsed to a default that came from nowhere. `values` is now a non-empty tuple, with a runtime check for a list built dynamically and asserted past. **`version` was optional on the legacy output type (#11).** It is deprecated, but `exportJSON()` writes it unconditionally, so making it optional at the base took that promise away from every consumer of a legacy export in order to describe a case they are not in. It is required again, and relaxed in the two places it is genuinely absent: `SerializedPartial` (a compact export omits it) and `LexicalUpdateJSON` (parsing drops it outright). This is what caught `$exportNodeJSON` promising the full type while returning whichever form is ambient; it now returns the `SerializedPartial` that both forms satisfy. **`SerializedPartial` did not recurse through children (#9).** Every node in a compact document is compact, not just the root, but `Partial<T>` made the `children` array optional while still promising that everything in it was fully serialized. An element now relaxes its children too; a node that has none is not given one. **Compact output needed a cast to be parsed (#8).** `parseEditorState` accepts `CompactSerializedEditorState` as well, which is what makes the compact form parseable at all — the casts are gone from the round-trip tests. **The codegen interpolated names without checking them (#13).** Schema keys, field names, accessor and predicate names go into the generated JavaScript as identifiers and property accesses. Anything that is not a plain identifier was a syntax error reported against generated code rather than against the schema that caused it, and a name the emitted code binds itself (`json`, `node`, `self`, `v`, `n`) or a reserved word produced code that reads something else. Both are refused now, named for the class whose schema caused it. Lookup-table names are derived by upper-casing, which is not injective, so two different tables claiming one name is refused rather than silently letting the second replace the first under a name the first class's code already reads. ## Test plan ### Before The two `unionValue` bugs, as tests against the branch: ``` × an alias whose target is the inner default is rejected AssertionError: expected 'fallback' to be '' // Object.is equality × a member comparator is not run on another member's values AssertionError: expected true to be false // Object.is equality ``` `enumValue([])` compiled and produced a schema with an empty domain. The compact round-trip tests needed `editor.parseEditorState({root: compact} as never)`. No test could reach the codegen's name handling, because every name in the manifest is an ordinary identifier. ### After ``` $ pnpm run test-unit Test Files 338 passed (338) Tests 6310 passed | 1 skipped (6311) $ pnpm run generate-node-json # regenerated modules match the checked-in files $ pnpm run tsc && pnpm run tsc-website && pnpm run flow $ pnpm run lint && pnpm run prettier ``` New tests cover each finding: the alias and comparator cases in `LexicalSchema.test.ts`, the empty enum (rejected by the type and at runtime), the `version` and children shapes as type assertions, and the codegen's refusals in a new `scripts/__tests__/unit/generateNodeJSON.test.ts`. Reverting the recursion in `SerializedPartial` fails the children assertions under `tsc`. Not exercised: no browser or E2E run — every change is a type or a pure combinator. Co-Authored-By: Claude Opus 5 <[email protected]>
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
Make Lexical editors work when their contentEditable is inside a DOM ShadowRoot, using platform APIs only — no emulation of browser selection facilities.
When a selection is inside a shadow tree the browser retargets Selection.anchorNode/focusNode/getRangeAt to the shadow host, and document.activeElement to the host, which previously prevented Lexical from resolving the selection back to its nodes.
Core (lexical):
@lexical/clipboard: resolve the copy guard's selection through shadow roots.
Playground: add a "Render in Shadow DOM" setting that portals the editor into an open shadow root, with an e2e spec covering typing, word selection, formatting and deletion.
Add a dev-examples/shadow-dom project and browser unit tests, since jsdom does not implement the shadow-DOM selection APIs.
Closes meta#7790
Closes meta#8125
RE meta#6709 meta#2119 meta#8659
Test plan
New browser unit and e2e tests