Skip to content

[lexical-playground] Refactor: migrate playground HTML import to DOMImportExtension - #6

Closed
etrepum wants to merge 1 commit into
mainfrom
claude/upbeat-dijkstra-DUTXl
Closed

etrepum wants to merge 1 commit into
mainfrom
claude/upbeat-dijkstra-DUTXl

Conversation

@etrepum

@etrepum etrepum commented May 28, 2026

Copy link
Copy Markdown
Owner

Description

Replace the legacy static importDOM machinery with the new DOMImportExtension pipeline across every playground node and remove the html config from the editor:

  • Drop every static importDOM / $config().importDOM on playground nodes and export an equivalent defineImportRule(...) from each node file (Image, Tweet, YouTube, Figma-via-rendered-iframe, Equation, Mention, Poll, DateTime, PageBreak, Excalidraw, LayoutContainer, LayoutItem, CollapsibleContainer/Content/Title).
  • Bundle the rules into a new PlaygroundImportExtension together with a playground-specific inline-style overlay that mirrors the legacy buildHTMLConfig's span-style wrapping for font-size, color, and background-color.
  • Move the legacy <p> -> <div role="paragraph"> export fixup for ParagraphNode out of html.export and into a PlaygroundDOMRenderExtension using DOMRenderExtension overrides.
  • Wire the per-package import extensions (Core, RichText, List, Link, Table, Code, HorizontalRule) and ClipboardDOMImportExtension into the AppExtension dependency graph, and delete buildHTMLConfig.tsx along with the html: buildHTMLConfig() field on the editor.
  • Update unit tests that exercised the legacy $generateNodesFromDOM path to drive the new $generateNodesFromDOMViaExtension pipeline.

Test plan

Before

Insert relevant screenshots/recordings/automated-tests

After

Insert relevant screenshots/recordings/automated-tests

…mportExtension

Replace the legacy static importDOM machinery with the new
DOMImportExtension pipeline across every playground node and remove the
html config from the editor:

- Drop every `static importDOM` / `$config().importDOM` on playground
  nodes and export an equivalent `defineImportRule(...)` from each node
  file (Image, Tweet, YouTube, Figma-via-rendered-iframe, Equation,
  Mention, Poll, DateTime, PageBreak, Excalidraw, LayoutContainer,
  LayoutItem, CollapsibleContainer/Content/Title).
- Bundle the rules into a new `PlaygroundImportExtension` together with
  a playground-specific inline-style overlay that mirrors the legacy
  `buildHTMLConfig`'s span-style wrapping for font-size, color, and
  background-color.
- Move the legacy `<p>` -> `<div role="paragraph">` export fixup for
  ParagraphNode out of `html.export` and into a `PlaygroundDOMRenderExtension`
  using `DOMRenderExtension` overrides.
- Wire the per-package import extensions (Core, RichText, List, Link,
  Table, Code, HorizontalRule) and `ClipboardDOMImportExtension` into
  the AppExtension dependency graph, and delete `buildHTMLConfig.tsx`
  along with the `html: buildHTMLConfig()` field on the editor.
- Update unit tests that exercised the legacy `$generateNodesFromDOM`
  path to drive the new `$generateNodesFromDOMViaExtension` pipeline.

https://claude.ai/code/session_01QRiVwbqog5CGzuGmexcvjG
@vercel

vercel Bot commented May 28, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
lexical-lexical-website Ready Ready Preview, Comment May 28, 2026 2:23pm

@etrepum

etrepum commented May 28, 2026

Copy link
Copy Markdown
Owner Author

Wrong repo

@etrepum etrepum closed this May 28, 2026
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]>
etrepum pushed a commit that referenced this pull request Oct 18, 2026
…erences on export

## Description

Export escaped the `&` of text that reads as a decimal character reference (`\&#65;`) but not of one that reads as a hex or named reference (`&#x41;`, `&amp;`), which GitHub and other CommonMark readers turn into a character, nor of one split across adjacent text nodes (`&#6` + `5;`), which is written as one reference. It now escapes those too.

## Test plan

### Before

```
$ vitest run --project unit packages/lexical-markdown/src/__tests__/unit/CodeSpanEscapes.test.ts -t "other readers"
     × escapes the & of text ["&#x41; &amp;"] that other readers take as a reference
     × escapes the & of text ["&#6","5;"] that other readers take as a reference
     × escapes the & of text ["&am","p;"] that other readers take as a reference
AssertionError: expected '&#x41; &amp;' to be '\&#x41; \&amp;' // Object.is equality
AssertionError: expected '&#65;' to be '\&#65;' // Object.is equality
AssertionError: expected '&amp;' to be '\&amp;' // Object.is equality
```

### After

```
$ vitest run --project unit packages/lexical-markdown
```

All pass.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
etrepum pushed a commit that referenced this pull request Oct 22, 2026
…thin its own text node

## Description

Export escaped the `&` of a character reference that following text nodes complete (`&#6` + `5;`), by joining the text of the next sibling text nodes, which missed siblings that aren't text nodes anyway. That lookahead is dropped: a reference written within one text node is still escaped (`\&#65;`), and one split across nodes is an edge case left as it is. The markdown entry is 87 B smaller (min+gzip 10554 to 10467).

## Test plan

### Before

```
$ vitest run --project unit packages/lexical-markdown
     × escapes the & of text ["&#6","5;"] that other readers take as a reference
     × escapes a reference completed by text with a format Markdown omits
      Tests  4 failed | 719 passed (723)
```

(with the lookahead removed, before removing its tests)

### After

```
$ vitest run --project unit packages/lexical-markdown
      Tests  717 passed (717)
```

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

This branch was successfully deployed

1 active deployment
Preview — def8ba88 Deployed May 28, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants