Skip to content

[lexical][lexical-html] Bug Fix: emit a terminating <br> so a trailing line break survives HTML export - #8765

Merged
etrepum merged 8 commits into
meta:mainfrom
potatowagon:jv-managed-linebreak-import
Aug 31, 2026
Merged

etrepum merged 8 commits into
meta:mainfrom
potatowagon:jv-managed-linebreak-import

Conversation

@potatowagon

@potatowagon potatowagon commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Description

A <br> that is the last (or only) child of a block element is not rendered by browsers, so both HTML importers deliberately drop it (isLastChildInBlockNode / isOnlyChildInBlockNode). That rule is correct for pasted HTML, but it meant a trailing LineBreakNode was lost on every export → import round trip, and a paragraph holding a single LineBreakNode came back empty.

Earlier revisions of this PR fixed that on the import side, keeping an unmarked trailing <br>. This revision reverts that and fixes the export side instead, because measurement showed the import-side gate regressed the common paste path.

Why the export side

Measured at line-height: 20px:

markup Chromium Firefox
<p>a</p> 20px 20px
<p>a<br></p> 20px 20px
<p>a<br><br></p> 40px 40px

A lone trailing <br> renders as nothing, so an application cannot express a visible trailing break that way — there is no content there to preserve. And both engines' own contenteditable emit <p>a<br><br></p> for a trailing soft break (a + Shift+Enter). <br><br> is the platform's annotation-free encoding, and Lexical's existing import rules already read it back as exactly one line break.

The defect was that Lexical's exporter wrote <p>a<br></p> — markup no browser produces for that content. The reconciler already solves this in the live DOM by appending a managed terminator <br> (ElementDOMSlot.insertManagedLineBreak); the exporter had no equivalent.

What this PR does

Emit the same terminator on export, when a block element's last exported child came from a LineBreakNode and the DOM it produced is a <br>, carrying the same data-lexical-managed-linebreak="true" marker the reconciler writes. An export and a scrape of the live DOM then describe a trailing break identically, and a consumer can tell the terminator apart from authored content.

The marker is metadata, not load-bearing — both importers still match on position, so HTML through a sanitizer that strips unknown data-* attributes round-trips unchanged (there is a test). No import rule keys off it, and no new public API: the attribute name is a literal with a comment pointing at the reconciler.

This lives in the @lexical/html exporter walk rather than a LineBreakNode.exportDOM override, because block-ness of the parent is only knowable there — when a leaf's exportDOM runs, the parent's element does not exist yet. Export and import gate on the same isBlockDomNode predicate, so a <br> gets a terminator exactly when an importer would have dropped it.

Behaviour

Measured on this branch, both importers agreeing:

trailing LineBreakNodes exported HTML re-imported
0 (empty block) <p><br></p> 0
1 <p>2<br><br data-lexical-managed-linebreak="true"></p> 1
2 <p>2<br><br><br data-lexical-managed-linebreak="true"></p> 2
3 <p>2<br><br><br><br data-lexical-managed-linebreak="true"></p> 3

Externally authored HTML is unchanged from main:

input result
<p>2<br></p> [text] — no phantom blank line
<p><br></p> [] — empty block
<p>2<br><br></p> [text, linebreak] — the platform's encoding, one break

The import rules are untouched. Code blocks, which export as <pre>, were losing a trailing newline the same way and are fixed by the same change. A break ending an inline element (<a>x<br></a>) gets no terminator, since nothing would drop it.

Cost

Exported HTML gains one <br> per trailing break. A naive html-to-text converter will count two newlines for a<br><br> — but it would do the same for Chromium's and Firefox's own contenteditable output, so this is no worse than the platform, which is the right bar for an interop format. The marker makes the terminator identifiable for consumers that want to skip it.

Also in this branch

  • The merge of main that this PR needed (it was 185 commits behind, and LineBreakNode had since moved from static importDOM() to $config()).
  • The revert of the import-side gate: the gate in both importers, the isManagedLineBreak helper and its lexical export, and the repurposed LexicalEventHelpers case.
  • Kept from the earlier revision: the isManagedLineBreak → isEditorManagedLineBreak rename in LexicalMutations, which is clearer on its own.

Test plan

New packages/lexical-html/src/__tests__/unit/LineBreakRoundTrip.test.ts, 15 cases covering both importers — $generateNodesFromDOM (which runs LineBreakNode's $config() importDOM) and $generateNodesFromDOMViaExtension (which runs coreImportRules' LineBreakRule). Four cases are guards that must pass either way, including that <p>a<br></p> from outside Lexical still imports without a line break.

Both importers are independently covered, confirmed by mutation testing: breaking only LineBreakRule fails exactly the four $generateNodesFromDOMViaExtension cases; breaking only the $config() importer fails exactly the four $generateNodesFromDOM cases.

Before

$ npx vitest run packages/lexical-html/src/__tests__/unit/LineBreakRoundTrip.test.ts

× a trailing line break exports with a terminating <br>
× a lone line break exports with a terminating <br>
× the exported terminator carries the reconciler marker
× restores a trailing line break                          (x2, one per importer)
× restores a lone line break                              (x2)
× restores consecutive trailing line breaks                (x2)
× restores a trailing line break with the marker stripped  (x2)

AssertionError: expected '<p><br></p>' to be '<p><br><br data-lexical-managed-lineb…'
AssertionError: expected <br></br> to have a length of 2 but got 1
AssertionError: expected [ 'text' ] to deeply equal [ 'text', 'linebreak' ]
AssertionError: expected [] to deeply equal [ 'linebreak' ]
AssertionError: expected [ 'text', 'linebreak' ] to deeply equal [ 'text', 'linebreak', 'linebreak' ]
 Test Files  1 failed (1)
      Tests  11 failed | 4 passed (15)

After

$ npx vitest run packages/lexical-html/src/__tests__/unit/LineBreakRoundTrip.test.ts
 Test Files  1 passed (1)
      Tests  15 passed (15)

$ npx vitest run                      # full jsdom unit suite
 Test Files  345 passed (345)
      Tests  6037 passed | 2 skipped (6039)

$ pnpm run test-browser               # vitest browser mode, chromium
 Test Files  24 passed (24)
      Tests  151 passed | 1 skipped (152)

$ npx cross-env E2E_BROWSER=chromium playwright test --project=chromium
  34 skipped
  835 passed

$ npx tsc --noEmit -p .               # clean
$ npx flow check
No errors!

WebKit could not be launched in the environment used, so Safari is unverified on both the rendering rule and the contenteditable convention above; Firefox and WebKit E2E were not run.

…naged line breaks

Follow-up to meta#8750 implementing @etrepum's approach from meta#7600.

meta#6395 dropped every trailing <br> in a block on import to match HTML's
non-rendering behavior, but that loses authored trailing breaks on
round-trip serialization. meta#8750 narrowed the drop to Safari's
Apple-interchange-newline clipboard artifact, but that gate doesn't fire
for ordinary structural/authored trailing breaks (or non-Safari pastes),
so the phantom-blank-line regression persists for those.

Instead, drop a trailing <br> only when it is a *managed* line break:
- data-lexical-managed-linebreak="true": the terminator Lexical's
  reconciler already injects via LexicalDOMSlot.setManagedLineBreak, so
  re-importing Lexical's own exported HTML stays idempotent.
- class="Apple-interchange-newline": Safari's clipboard transport artifact.

An ordinary authored trailing <br> carries neither marker and is now
preserved, so round-trip serialization to HTML is lossless while
rendering of external pasted HTML stays faithful. Browser-agnostic for
the Lexical-managed case.

Applies the same gate to both LineBreakNode.importDOM and the
@lexical/html coreImportRules LineBreakRule. Adds test coverage for the
preserved / managed / Apple-interchange cases.
@vercel

vercel Bot commented Jun 30, 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 31, 2026 5:08pm
lexical-playground Ready Ready Preview Aug 31, 2026 5:08pm

Request Review

@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 Jun 30, 2026
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Jun 30, 2026
Addresses review feedback: the new isManagedLineBreak in
LexicalLineBreakNode (inspects serialized markup — the
data-lexical-managed-linebreak attribute / Apple-interchange class to
decide whether to drop a parsed <br> on import) collided by name with
the pre-existing isManagedLineBreak in LexicalMutations (identifies a
line break the editor is actively managing in the live DOM via the
__lexicalLineBreak slot reference / node key). They work differently, so
the mutations one is renamed to isEditorManagedLineBreak and both now
carry cross-referencing comments.
@levensta

Copy link
Copy Markdown
Contributor

Looks like everything's ready here?

@levensta

Copy link
Copy Markdown
Contributor

Is there anything that prevents this PR from being merged now, other than the draft status? @etrepum @potatowagon

@etrepum

etrepum commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Claude claims that this is missing a case where the <br> is the only child of a block, here's the unedited response. I'm not sure if (1) is actually a thing that happens or if it's just guessing, I haven't looked at non-lexical HTML of this nature much recently. I don't think (2) actually matters, this Safari quirk probably isn't going to suddenly add additional classes or change the class it uses.


Code review — gate trailing <br> import drop on managed line breaks

Reviewed the diff (5 files, +75/−14). The change drops a trailing <br> on import only when it carries a "managed" marker (data-lexical-managed-linebreak="true" or class="Apple-interchange-newline"), preserving ordinary authored trailing breaks. Mechanically the diff is clean — the isEditorManagedLineBreak rename is internal-only with all three call sites updated, the new isManagedLineBreak export is wired through index.ts and coreImportRules.ts, and the test expectations are consistent. Findings below, most-severe first.

1. Unmarked browser-inserted trailing <br> is now preserved (phantom blank line) — coreImportRules.ts / LexicalLineBreakNode.importDOM

Pasting external HTML like <div>foo<br></div> or <p>foo<br></p> from a browser contenteditable, Google Docs, or a website: the trailing <br> carries neither marker, so it's now imported as a LineBreakNode → foo\n with an extra empty line. The deleted comment explicitly named "the trailing <br> browsers insert after the last text in a <div>" as a case to drop; that protection is gone in both import paths. This is the crux of the PR — preserving authored breaks necessarily preserves indistinguishable external browser-artifact breaks too. If extra trailing blank lines on some external pastes are an accepted cost of lossless round-trips, fine; if not, this needs an explicit decision before merge.

2. Apple-interchange detection uses exact string equality on the whole class attribute — LexicalLineBreakNode.ts

node.getAttribute('class') === 'Apple-interchange-newline' fails for any <br> whose class isn't byte-for-byte that single token: e.g. class="Apple-interchange-newline foo", a leading/trailing space, or reordered tokens → treated as authored → preserved → extra blank line. Use node.classList.contains('Apple-interchange-newline').

3. Docstring rationale doesn't match how Lexical exports HTML — LexicalLineBreakNode.ts

The comment justifies the marker via "Re-importing Lexical's own exported HTML", but clipboard/serialization goes through $generateHtmlFromNodes (exportDOM), and LineBreakNode has no exportDOM, so it emits a plain <br> with no marker. The data-lexical-managed-linebreak attribute only exists in the live contenteditable DOM (set by LexicalDOMSlot.setManagedLineBreak). So the marker fires only for raw live-DOM copies, not for exported HTML — the comment mis-models when this branch actually triggers.

4. "Lossless round-trip" claim is still violated for a single-linebreak paragraph — LexicalLineBreakNode.ts

isOnlyChildInBlockNode still drops the <br> unconditionally (not gated on managed). An authored paragraph containing exactly one LineBreakNode exports as <p><br></p>; on import the only-child <br> is dropped and the node is lost → empty paragraph. This contradicts the new "round-trip serialization to HTML stays lossless" comment sitting right next to it.

5. Drop predicate is duplicated across two import paths — LexicalLineBreakNode.ts + coreImportRules.ts

Both hardcode isOnlyChildInBlockNode(x) || (isLastChildInBlockNode(x) && isManagedLineBreak(x)). This PR had to edit both; a future change that updates only one will silently diverge the legacy importer from the extension importer. Consider a single shared $shouldDropImportedBr(node) helper.

etrepum pushed a commit to etrepum/lexical that referenced this pull request Aug 30, 2026
…reak on export

## Description

A `<br>` that is the last (or only) child of a block element is not rendered by
browsers, so both HTML importers deliberately drop it — `isLastChildInBlockNode`
and `isOnlyChildInBlockNode` in `LexicalLineBreakNode`, used by both
`LineBreakNode.importDOM` and `@lexical/html`'s `LineBreakRule`.

The reconciler already compensates for that rule in the live DOM: when an
element ends with a `LineBreakNode` it appends a managed terminator `<br>`
(`ElementDOMSlot.insertManagedLineBreak`) so the break actually renders. The
HTML exporter had no equivalent, so `$generateHtmlFromNodes` wrote a paragraph
ending in a `LineBreakNode` as `<p>a<br></p>` — HTML that renders as a single
line, and that every importer reads back without the break at all. A paragraph
holding a single `LineBreakNode` came back empty.

Emit the same terminator on export, when a block element's last exported child
came from a `LineBreakNode` and the DOM it produced is a `<br>`. The importers
drop the terminator and keep the authored break, so the round trip is lossless
with no change to the import rules — externally authored HTML such as
`<p>a<br></p>`, which a browser renders as one line, still imports without a
phantom blank line.

Export and import gate on the same `isBlockDomNode` predicate, so a `<br>` gets
a terminator exactly when an importer would have dropped it. That keeps the two
sides consistent for a break trailing an inline element (`<a>x<br></a>` — no
terminator, nothing dropped), for tags outside `BLOCK_TAG_RE` such as `<th>`,
and for a `domOverride` that wraps the `<br>` in another element. Code blocks,
which export as `<pre>`, were losing a trailing newline the same way and are
fixed by the same change.

This supersedes meta#8765, which addressed the same round-trip loss by relaxing the
import rules to keep unmarked trailing `<br>`s. Fixing the export side instead
avoids changing how externally authored HTML is pasted, needs no new public API,
and also covers the sole-child case that the import-side gate left lossy.

## Test plan

New test: `packages/lexical-html/src/__tests__/unit/LineBreakRoundTrip.test.ts`,
covering both importers (`$generateNodesFromDOM` and
`$generateNodesFromDOMViaExtension`). Four of its twelve cases are guards that
must pass either way: they assert the export shape is unchanged for an interior
break and for a break trailing an inline element, and that `<p>a<br></p>` from
outside Lexical still imports without a line break.

### Before

    $ npx vitest run packages/lexical-html/src/__tests__/unit/LineBreakRoundTrip.test.ts

         × a trailing line break exports with a terminating <br> 27ms
         × a lone line break exports with a terminating <br> 4ms
           × restores a trailing line break 32ms
           × restores a lone line break 11ms
           × restores consecutive trailing line breaks 11ms
           × restores a trailing line break 12ms
           × restores a lone line break 9ms
           × restores consecutive trailing line breaks 10ms
    ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 8 ⎯⎯⎯⎯⎯⎯⎯
    AssertionError: expected '<p><span style="white-space: pre-wrap…' to be '<p><span style="white-space: pre-wrap…' // Object.is equality
    AssertionError: expected '<p><br></p>' to be '<p><br><br></p>'  // Object.is equality
    AssertionError: expected [ 'text' ] to deeply equal [ 'text', 'linebreak' ]
    AssertionError: expected [] to deeply equal [ 'linebreak' ]
    AssertionError: expected [ 'text', 'linebreak' ] to deeply equal [ 'text', 'linebreak', 'linebreak' ]
     Test Files  1 failed (1)
          Tests  8 failed | 4 passed (12)

### After

    $ npx vitest run packages/lexical-html/src/__tests__/unit/LineBreakRoundTrip.test.ts
     Test Files  1 passed (1)
          Tests  12 passed (12)

    $ npx vitest run                      # full jsdom unit suite
     Test Files  316 passed (340)
          Tests  5839 passed | 1 skipped (5840)

    $ pnpm run test-browser               # vitest browser mode, chromium
     Test Files  24 passed (24)
          Tests  151 passed | 1 skipped (152)

    $ npx cross-env E2E_BROWSER=chromium playwright test --project=chromium
      34 skipped
      834 passed (18.3m)

    $ npx tsc --noEmit -p .               # clean
    $ npx flow check
    No errors!

The 24 unit test files not run by `npx vitest run` are the vitest browser-mode
set, which `pnpm run test-browser` covers. Firefox and WebKit E2E were not
exercised.

The rendering rule this change relies on was measured rather than assumed. At
`line-height: 20px`, in both Chromium and Firefox, `<p>a</p>` and `<p>a<br></p>`
are both 20px while `<p>a<br><br></p>` is 40px — a lone trailing `<br>` does not
render. Both engines' own `contenteditable` also emit `<p>a<br><br></p>` for a
trailing soft break, so the terminator emitted here is the platform's own
encoding of that content, and Lexical's existing import rules already read it
back as a single line break. WebKit could not be launched in this environment,
so Safari is unverified on both points.
claude added 3 commits August 30, 2026 21:26
## Description

meta#8765 branched from 335410a and is 185 commits behind `main`, so it no longer
applies. Merge `main` in (rather than rebasing, which would invalidate the
contributor's checkout) and resolve the three conflicts its diff creates:

- `LexicalLineBreakNode.ts`: `main` moved the `<br>` importer out of
  `static importDOM()` into `$config()`, and dropped `static importJSON()`.
  Take `main`'s shape and carry meta#8765's managed-line-break gate into the
  `$config()` importer.
- `LexicalMutations.ts`: meta#8765 renamed the local helper to
  `isEditorManagedLineBreak`; `main` added an adjacent
  `isDecoratorBoundaryAnchorDOM` check for the decorator boundary anchors
  from meta#8922. Keep both.
- `coreImportRules.ts`: keep meta#8765's updated `LineBreakRule` comment, but take
  `main`'s `defineImportRule(` without the hand-written `/* @__PURE__ */` —
  those annotations are injected by `@lexical/compiler` at build time now and a
  hand-written one is a lint error.

No behavior change beyond bringing the branch up to date; meta#8765's import-side
gate is preserved exactly as its author wrote it.
…de trailing-<br> gate

## Description

meta#8765 made both HTML importers keep a trailing `<br>` unless it carries
`data-lexical-managed-linebreak="true"` or `class="Apple-interchange-newline"`,
so that a trailing `LineBreakNode` survives an export/import round trip. Revert
that; the following commit fixes the same round-trip loss on the export side
instead. Three reasons the import-side gate is the wrong half:

- It does not fix the case it targets. `exportDOM` never writes
  `data-lexical-managed-linebreak` — only the reconciler writes it, into the
  live DOM (`ElementDOMSlot.insertManagedLineBreak`). The marker is absent from
  exactly the HTML whose round trip the change is about.
- The `Apple-interchange-newline` branch is unreachable for real Safari
  payloads. Safari puts that sentinel at the top level of the clipboard
  fragment, whose parent is `<body>`; `BODY` is not in `BLOCK_TAG_RE`, so
  `isLastChildInBlockNode` already returns false there.
- It regresses the common paste path. Measured at `line-height: 20px`, in both
  Chromium and Firefox, `<p>a</p>` and `<p>a<br></p>` are both 20px while
  `<p>a<br><br></p>` is 40px — a lone trailing `<br>` does not render. Both
  engines' own `contenteditable` emit `<p>a<br><br></p>` for a trailing soft
  break, so `<br><br>` is the platform's encoding and the existing rules
  already read it back as one line break. Keeping unmarked trailing `<br>`s
  turns that into two, and gives externally authored `<p>a<br></p>` a blank
  line no browser renders.

It also left `isOnlyChildInBlockNode` dropping unconditionally, so a paragraph
holding a single `LineBreakNode` still came back empty.

Reverted: the gate in `LineBreakNode`'s `$config()` importer and in
`coreImportRules`' `LineBreakRule`, the `isManagedLineBreak` helper and its
`lexical` export, and the repurposed `last br in a block node is ignored` case
in `LexicalEventHelpers`. Kept: the `isEditorManagedLineBreak` rename in
`LexicalMutations`, which is clearer on its own; its comment no longer
cross-references the removed helper.

After this commit the only delta from `main` is that rename.

## Test plan

    $ npx vitest run packages/lexical-utils/src/__tests__/unit/LexicalEventHelpers.test.tsx
     Test Files  1 passed (1)
…reak on export

## Description

A `<br>` that is the last (or only) child of a block element is not rendered by
browsers, so both HTML importers deliberately drop it — `isLastChildInBlockNode`
and `isOnlyChildInBlockNode` in `LexicalLineBreakNode`, used by both
`LineBreakNode.importDOM` and `@lexical/html`'s `LineBreakRule`.

The reconciler already compensates for that rule in the live DOM: when an
element ends with a `LineBreakNode` it appends a managed terminator `<br>`
(`ElementDOMSlot.insertManagedLineBreak`) so the break actually renders. The
HTML exporter had no equivalent, so `$generateHtmlFromNodes` wrote a paragraph
ending in a `LineBreakNode` as `<p>a<br></p>` — HTML that renders as a single
line, and that every importer reads back without the break at all. A paragraph
holding a single `LineBreakNode` came back empty.

Emit the same terminator on export, when a block element's last exported child
came from a `LineBreakNode` and the DOM it produced is a `<br>`. The importers
drop the terminator and keep the authored break, so the round trip is lossless
with no change to the import rules — externally authored HTML such as
`<p>a<br></p>`, which a browser renders as one line, still imports without a
phantom blank line.

Export and import gate on the same `isBlockDomNode` predicate, so a `<br>` gets
a terminator exactly when an importer would have dropped it. That keeps the two
sides consistent for a break trailing an inline element (`<a>x<br></a>` — no
terminator, nothing dropped), for tags outside `BLOCK_TAG_RE` such as `<th>`,
and for a `domOverride` that wraps the `<br>` in another element. Code blocks,
which export as `<pre>`, were losing a trailing newline the same way and are
fixed by the same change.

This supersedes meta#8765, which addressed the same round-trip loss by relaxing the
import rules to keep unmarked trailing `<br>`s. Fixing the export side instead
avoids changing how externally authored HTML is pasted, needs no new public API,
and also covers the sole-child case that the import-side gate left lossy.

## Test plan

New test: `packages/lexical-html/src/__tests__/unit/LineBreakRoundTrip.test.ts`,
covering both importers (`$generateNodesFromDOM` and
`$generateNodesFromDOMViaExtension`). Four of its twelve cases are guards that
must pass either way: they assert the export shape is unchanged for an interior
break and for a break trailing an inline element, and that `<p>a<br></p>` from
outside Lexical still imports without a line break.

### Before

    $ npx vitest run packages/lexical-html/src/__tests__/unit/LineBreakRoundTrip.test.ts

         × a trailing line break exports with a terminating <br> 27ms
         × a lone line break exports with a terminating <br> 4ms
           × restores a trailing line break 32ms
           × restores a lone line break 11ms
           × restores consecutive trailing line breaks 11ms
           × restores a trailing line break 12ms
           × restores a lone line break 9ms
           × restores consecutive trailing line breaks 10ms
    ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 8 ⎯⎯⎯⎯⎯⎯⎯
    AssertionError: expected '<p><span style="white-space: pre-wrap…' to be '<p><span style="white-space: pre-wrap…' // Object.is equality
    AssertionError: expected '<p><br></p>' to be '<p><br><br></p>'  // Object.is equality
    AssertionError: expected [ 'text' ] to deeply equal [ 'text', 'linebreak' ]
    AssertionError: expected [] to deeply equal [ 'linebreak' ]
    AssertionError: expected [ 'text', 'linebreak' ] to deeply equal [ 'text', 'linebreak', 'linebreak' ]
     Test Files  1 failed (1)
          Tests  8 failed | 4 passed (12)

### After

    $ npx vitest run packages/lexical-html/src/__tests__/unit/LineBreakRoundTrip.test.ts
     Test Files  1 passed (1)
          Tests  12 passed (12)

    $ npx vitest run                      # full jsdom unit suite
     Test Files  316 passed (340)
          Tests  5839 passed | 1 skipped (5840)

    $ pnpm run test-browser               # vitest browser mode, chromium
     Test Files  24 passed (24)
          Tests  151 passed | 1 skipped (152)

    $ npx cross-env E2E_BROWSER=chromium playwright test --project=chromium
      34 skipped
      834 passed (18.3m)

    $ npx tsc --noEmit -p .               # clean
    $ npx flow check
    No errors!

The 24 unit test files not run by `npx vitest run` are the vitest browser-mode
set, which `pnpm run test-browser` covers. Firefox and WebKit E2E were not
exercised.

The rendering rule this change relies on was measured rather than assumed. At
`line-height: 20px`, in both Chromium and Firefox, `<p>a</p>` and `<p>a<br></p>`
are both 20px while `<p>a<br><br></p>` is 40px — a lone trailing `<br>` does not
render. Both engines' own `contenteditable` also emit `<p>a<br><br></p>` for a
trailing soft break, so the terminator emitted here is the platform's own
encoding of that content, and Lexical's existing import rules already read it
back as a single line break. WebKit could not be launched in this environment,
so Safari is unverified on both points.
claude and others added 2 commits August 30, 2026 22:09
…reak on export

## Description

A `<br>` that is the last (or only) child of a block element is not rendered by
browsers, so both HTML importers deliberately drop it — `isLastChildInBlockNode`
and `isOnlyChildInBlockNode` in `LexicalLineBreakNode`, used by both
`LineBreakNode.importDOM` and `@lexical/html`'s `LineBreakRule`.

The reconciler already compensates for that rule in the live DOM: when an
element ends with a `LineBreakNode` it appends a managed terminator `<br>`
(`ElementDOMSlot.insertManagedLineBreak`) so the break actually renders. The
HTML exporter had no equivalent, so `$generateHtmlFromNodes` wrote a paragraph
ending in a `LineBreakNode` as `<p>a<br></p>` — HTML that renders as a single
line, and that every importer reads back without the break at all. A paragraph
holding a single `LineBreakNode` came back empty.

Emit the same terminator on export, when a block element's last exported child
came from a `LineBreakNode` and the DOM it produced is a `<br>`. The importers
drop the terminator and keep the authored break, so the round trip is lossless
with no change to the import rules — externally authored HTML such as
`<p>a<br></p>`, which a browser renders as one line, still imports without a
phantom blank line.

Export and import gate on the same `isBlockDomNode` predicate, so a `<br>` gets
a terminator exactly when an importer would have dropped it. That keeps the two
sides consistent for a break trailing an inline element (`<a>x<br></a>` — no
terminator, nothing dropped), for tags outside `BLOCK_TAG_RE` such as `<th>`,
and for a `domOverride` that wraps the `<br>` in another element. Code blocks,
which export as `<pre>`, were losing a trailing newline the same way and are
fixed by the same change.

This replaces the import-side gate reverted in the preceding commit (meta#8765's
approach). Fixing the export side instead avoids changing how externally
authored HTML is pasted, needs no new public API, and also covers the
sole-child case that the import-side gate left lossy.

## Test plan

New test: `packages/lexical-html/src/__tests__/unit/LineBreakRoundTrip.test.ts`,
covering both importers (`$generateNodesFromDOM` and
`$generateNodesFromDOMViaExtension`). Four of its twelve cases are guards that
must pass either way: they assert the export shape is unchanged for an interior
break and for a break trailing an inline element, and that `<p>a<br></p>` from
outside Lexical still imports without a line break.

### Before

    $ npx vitest run packages/lexical-html/src/__tests__/unit/LineBreakRoundTrip.test.ts

         × a trailing line break exports with a terminating <br> 27ms
         × a lone line break exports with a terminating <br> 4ms
           × restores a trailing line break 32ms
           × restores a lone line break 11ms
           × restores consecutive trailing line breaks 11ms
           × restores a trailing line break 12ms
           × restores a lone line break 9ms
           × restores consecutive trailing line breaks 10ms
    ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 8 ⎯⎯⎯⎯⎯⎯⎯
    AssertionError: expected '<p><span style="white-space: pre-wrap…' to be '<p><span style="white-space: pre-wrap…' // Object.is equality
    AssertionError: expected '<p><br></p>' to be '<p><br><br></p>'  // Object.is equality
    AssertionError: expected [ 'text' ] to deeply equal [ 'text', 'linebreak' ]
    AssertionError: expected [] to deeply equal [ 'linebreak' ]
    AssertionError: expected [ 'text', 'linebreak' ] to deeply equal [ 'text', 'linebreak', 'linebreak' ]
     Test Files  1 failed (1)
          Tests  8 failed | 4 passed (12)

### After

    $ npx vitest run packages/lexical-html/src/__tests__/unit/LineBreakRoundTrip.test.ts
     Test Files  1 passed (1)
          Tests  12 passed (12)

    $ npx vitest run                      # full jsdom unit suite
     Test Files  345 passed (345)
          Tests  6034 passed | 2 skipped (6036)

    $ pnpm run test-browser               # vitest browser mode, chromium
     Test Files  24 passed (24)
          Tests  151 passed | 1 skipped (152)

    $ npx cross-env E2E_BROWSER=chromium playwright test --project=chromium
      34 skipped
      835 passed (16.6m)

    $ npx tsc --noEmit -p .               # clean
    $ npx flow check
    No errors!

Firefox and WebKit E2E were not exercised.

The rendering rule this change relies on was measured rather than assumed. At
`line-height: 20px`, in both Chromium and Firefox, `<p>a</p>` and `<p>a<br></p>`
are both 20px while `<p>a<br><br></p>` is 40px — a lone trailing `<br>` does not
render. Both engines' own `contenteditable` also emit `<p>a<br><br></p>` for a
trailing soft break, so the terminator emitted here is the platform's own
encoding of that content, and Lexical's existing import rules already read it
back as a single line break. WebKit could not be launched in this environment,
so Safari is unverified on both points.
etrepum pushed a commit to etrepum/lexical that referenced this pull request Aug 31, 2026
…reak on export

## Description

A `<br>` that is the last (or only) child of a block element is not rendered by
browsers, so both HTML importers deliberately drop it — `isLastChildInBlockNode`
and `isOnlyChildInBlockNode` in `LexicalLineBreakNode`, used by both
`LineBreakNode.importDOM` and `@lexical/html`'s `LineBreakRule`.

The reconciler already compensates for that rule in the live DOM: when an
element ends with a `LineBreakNode` it appends a managed terminator `<br>`
(`ElementDOMSlot.insertManagedLineBreak`) so the break actually renders. The
HTML exporter had no equivalent, so `$generateHtmlFromNodes` wrote a paragraph
ending in a `LineBreakNode` as `<p>a<br></p>` — HTML that renders as a single
line, and that every importer reads back without the break at all. A paragraph
holding a single `LineBreakNode` came back empty.

Emit the same terminator on export, when a block element's last exported child
came from a `LineBreakNode` and the DOM it produced is a `<br>`, carrying the
same `data-lexical-managed-linebreak="true"` marker the reconciler writes. An
export and a scrape of the live DOM then describe a trailing break identically,
and a consumer can tell the terminator apart from authored content. The marker
is metadata, not load-bearing: the importers match on position, so HTML that
has been through a sanitizer that strips unknown `data-*` attributes still
round-trips (covered by a test). The importers
drop the terminator and keep the authored break, so the round trip is lossless
with no change to the import rules — externally authored HTML such as
`<p>a<br></p>`, which a browser renders as one line, still imports without a
phantom blank line.

Export and import gate on the same `isBlockDomNode` predicate, so a `<br>` gets
a terminator exactly when an importer would have dropped it. That keeps the two
sides consistent for a break trailing an inline element (`<a>x<br></a>` — no
terminator, nothing dropped), for tags outside `BLOCK_TAG_RE` such as `<th>`,
and for a `domOverride` that wraps the `<br>` in another element. Code blocks,
which export as `<pre>`, were losing a trailing newline the same way and are
fixed by the same change.

This replaces the import-side gate reverted in the preceding commit (meta#8765's
approach). Fixing the export side instead avoids changing how externally
authored HTML is pasted, needs no new public API, and also covers the
sole-child case that the import-side gate left lossy.

## Test plan

New test: `packages/lexical-html/src/__tests__/unit/LineBreakRoundTrip.test.ts`,
covering both importers (`$generateNodesFromDOM`, which runs `LineBreakNode`'s
`$config()` `importDOM`, and `$generateNodesFromDOMViaExtension`, which runs
`coreImportRules`' `LineBreakRule`). Mutation-tested to confirm the two are
independently covered: breaking only `LineBreakRule` fails exactly the four
`$generateNodesFromDOMViaExtension` cases, and breaking only the `$config()`
importer fails exactly the four `$generateNodesFromDOM` cases. Four of its fifteen cases are guards that
must pass either way: they assert the export shape is unchanged for an interior
break and for a break trailing an inline element, and that `<p>a<br></p>` from
outside Lexical still imports without a line break.

### Before

    $ npx vitest run packages/lexical-html/src/__tests__/unit/LineBreakRoundTrip.test.ts

    × a trailing line break exports with a terminating <br> 32ms
    × a lone line break exports with a terminating <br> 4ms
    × the exported terminator carries the reconciler marker 26ms
    × restores a trailing line break 22ms
    × restores a lone line break 15ms
    × restores consecutive trailing line breaks 13ms
    × restores a trailing line break with the marker stripped 14ms
    × restores a trailing line break 14ms
    × restores a lone line break 15ms
    × restores consecutive trailing line breaks 19ms
    × restores a trailing line break with the marker stripped 14ms
    ⎯⎯⎯⎯⎯⎯ Failed Tests 11 ⎯⎯⎯⎯⎯⎯⎯
    AssertionError: expected '<p><span style="white-space: pre-wrap…' to be '<p><span style="white-space: pre-wrap…' // Object.is equality
    AssertionError: expected '<p><br></p>' to be '<p><br><br data-lexical-managed-lineb…' // Object.is equality
    AssertionError: expected <br></br> to have a length of 2 but got 1
    AssertionError: expected [ 'text' ] to deeply equal [ 'text', 'linebreak' ]
    AssertionError: expected [] to deeply equal [ 'linebreak' ]
    AssertionError: expected [ 'text', 'linebreak' ] to deeply equal [ 'text', 'linebreak', 'linebreak' ]
    AssertionError: expected [ 'text' ] to deeply equal [ 'text', 'linebreak' ]
    Test Files  1 failed (1)
    Tests  11 failed | 4 passed (15)

### After

    $ npx vitest run packages/lexical-html/src/__tests__/unit/LineBreakRoundTrip.test.ts
     Test Files  1 passed (1)
          Tests  15 passed (15)

    $ npx vitest run                      # full jsdom unit suite
     Test Files  345 passed (345)
          Tests  6037 passed | 2 skipped (6039)

    $ pnpm run test-browser               # vitest browser mode, chromium
     Test Files  24 passed (24)
          Tests  151 passed | 1 skipped (152)

    $ npx cross-env E2E_BROWSER=chromium playwright test --project=chromium
      34 skipped
      835 passed (16.6m)

    $ npx tsc --noEmit -p .               # clean
    $ npx flow check
    No errors!

Firefox and WebKit E2E were not exercised.

The rendering rule this change relies on was measured rather than assumed. At
`line-height: 20px`, in both Chromium and Firefox, `<p>a</p>` and `<p>a<br></p>`
are both 20px while `<p>a<br><br></p>` is 40px — a lone trailing `<br>` does not
render. Both engines' own `contenteditable` also emit `<p>a<br><br></p>` for a
trailing soft break, so the terminator emitted here is the platform's own
encoding of that content, and Lexical's existing import rules already read it
back as a single line break. WebKit could not be launched in this environment,
so Safari is unverified on both points.
etrepum pushed a commit to etrepum/lexical that referenced this pull request Aug 31, 2026
…reak on export

## Description

A `<br>` that is the last (or only) child of a block element is not rendered by
browsers, so both HTML importers deliberately drop it — `isLastChildInBlockNode`
and `isOnlyChildInBlockNode` in `LexicalLineBreakNode`, used by both
`LineBreakNode.importDOM` and `@lexical/html`'s `LineBreakRule`.

The reconciler already compensates for that rule in the live DOM: when an
element ends with a `LineBreakNode` it appends a managed terminator `<br>`
(`ElementDOMSlot.insertManagedLineBreak`) so the break actually renders. The
HTML exporter had no equivalent, so `$generateHtmlFromNodes` wrote a paragraph
ending in a `LineBreakNode` as `<p>a<br></p>` — HTML that renders as a single
line, and that every importer reads back without the break at all. A paragraph
holding a single `LineBreakNode` came back empty.

Emit the same terminator on export, when a block element's last exported child
came from a `LineBreakNode` and the DOM it produced is a `<br>`, carrying the
same `data-lexical-managed-linebreak="true"` marker the reconciler writes. An
export and a scrape of the live DOM then describe a trailing break identically,
and a consumer can tell the terminator apart from authored content. The marker
is metadata, not load-bearing: the importers match on position, so HTML that
has been through a sanitizer that strips unknown `data-*` attributes still
round-trips (covered by a test). The importers
drop the terminator and keep the authored break, so the round trip is lossless
with no change to the import rules — externally authored HTML such as
`<p>a<br></p>`, which a browser renders as one line, still imports without a
phantom blank line.

Export and import gate on the same `isBlockDomNode` predicate, so a `<br>` gets
a terminator exactly when an importer would have dropped it. That keeps the two
sides consistent for a break trailing an inline element (`<a>x<br></a>` — no
terminator, nothing dropped), for tags outside `BLOCK_TAG_RE` such as `<th>`,
and for a `domOverride` that wraps the `<br>` in another element. Code blocks,
which export as `<pre>`, were losing a trailing newline the same way and are
fixed by the same change.

This replaces the import-side gate reverted in the preceding commit (meta#8765's
approach). Fixing the export side instead avoids changing how externally
authored HTML is pasted, needs no new public API, and also covers the
sole-child case that the import-side gate left lossy.

## Test plan

New test: `packages/lexical-html/src/__tests__/unit/LineBreakRoundTrip.test.ts`,
covering both importers (`$generateNodesFromDOM`, which runs `LineBreakNode`'s
`$config()` `importDOM`, and `$generateNodesFromDOMViaExtension`, which runs
`coreImportRules`' `LineBreakRule`). Mutation-tested to confirm the two are
independently covered: breaking only `LineBreakRule` fails exactly the four
`$generateNodesFromDOMViaExtension` cases, and breaking only the `$config()`
importer fails exactly the four `$generateNodesFromDOM` cases. Four of its fifteen cases are guards that
must pass either way: they assert the export shape is unchanged for an interior
break and for a break trailing an inline element, and that `<p>a<br></p>` from
outside Lexical still imports without a line break.

### Before

    $ npx vitest run packages/lexical-html/src/__tests__/unit/LineBreakRoundTrip.test.ts

    × a trailing line break exports with a terminating <br> 32ms
    × a lone line break exports with a terminating <br> 4ms
    × the exported terminator carries the reconciler marker 26ms
    × restores a trailing line break 22ms
    × restores a lone line break 15ms
    × restores consecutive trailing line breaks 13ms
    × restores a trailing line break with the marker stripped 14ms
    × restores a trailing line break 14ms
    × restores a lone line break 15ms
    × restores consecutive trailing line breaks 19ms
    × restores a trailing line break with the marker stripped 14ms
    ⎯⎯⎯⎯⎯⎯ Failed Tests 11 ⎯⎯⎯⎯⎯⎯⎯
    AssertionError: expected '<p><span style="white-space: pre-wrap…' to be '<p><span style="white-space: pre-wrap…' // Object.is equality
    AssertionError: expected '<p><br></p>' to be '<p><br><br data-lexical-managed-lineb…' // Object.is equality
    AssertionError: expected <br></br> to have a length of 2 but got 1
    AssertionError: expected [ 'text' ] to deeply equal [ 'text', 'linebreak' ]
    AssertionError: expected [] to deeply equal [ 'linebreak' ]
    AssertionError: expected [ 'text', 'linebreak' ] to deeply equal [ 'text', 'linebreak', 'linebreak' ]
    AssertionError: expected [ 'text' ] to deeply equal [ 'text', 'linebreak' ]
    Test Files  1 failed (1)
    Tests  11 failed | 4 passed (15)

### After

    $ npx vitest run packages/lexical-html/src/__tests__/unit/LineBreakRoundTrip.test.ts
     Test Files  1 passed (1)
          Tests  15 passed (15)

    $ npx vitest run                      # full jsdom unit suite
     Test Files  345 passed (345)
          Tests  6037 passed | 2 skipped (6039)

    $ pnpm run test-browser               # vitest browser mode, chromium
     Test Files  24 passed (24)
          Tests  151 passed | 1 skipped (152)

    $ npx cross-env E2E_BROWSER=chromium playwright test --project=chromium
      34 skipped
      835 passed (19.9m)

    $ npx tsc --noEmit -p .               # clean
    $ npx flow check
    No errors!

Firefox and WebKit E2E were not exercised.

The rendering rule this change relies on was measured rather than assumed. At
`line-height: 20px`, in both Chromium and Firefox, `<p>a</p>` and `<p>a<br></p>`
are both 20px while `<p>a<br><br></p>` is 40px — a lone trailing `<br>` does not
render. Both engines' own `contenteditable` also emit `<p>a<br><br></p>` for a
trailing soft break, so the terminator emitted here is the platform's own
encoding of that content, and Lexical's existing import rules already read it
back as a single line break. WebKit could not be launched in this environment,
so Safari is unverified on both points.
…ged line break

## Description

The terminating `<br>` the exporter appends after a trailing `LineBreakNode` is
the same construct the reconciler injects in the live DOM, but it was emitted
bare while the reconciler marks its own with
`data-lexical-managed-linebreak="true"`
(`ElementDOMSlot.insertManagedLineBreak`).

Write the same marker on export. An export and a scrape of the live DOM then
describe a trailing break identically, and a consumer reading the HTML can tell
the terminator apart from authored content rather than having to infer it from
position.

The marker is metadata, not load-bearing. Both importers still match on
position, so HTML that has passed through a sanitizer which strips unknown
`data-*` attributes round-trips exactly the same — there is a test for that. No
import rule keys off the marker, and no new public API: the attribute name is a
literal with a comment pointing at the reconciler, since `lexical` exports no
attribute-name constants today.

## Test plan

Three cases added to `LineBreakRoundTrip.test.ts` (12 -> 15): the exported
terminator carries the marker and the authored `<br>` does not; the two export
shapes include it; and a round trip still succeeds with the marker stripped.

### Before

    $ npx vitest run packages/lexical-html/src/__tests__/unit/LineBreakRoundTrip.test.ts

    × a trailing line break exports with a terminating <br> 34ms
    × a lone line break exports with a terminating <br> 4ms
    × the exported terminator carries the reconciler marker 28ms
    AssertionError: expected '<p><span style="white-space: pre-wrap…' to be '<p><span style="white-space: pre-wrap…'
    AssertionError: expected '<p><br><br></p>' to be '<p><br><br data-lexical-managed-lineb…'
    AssertionError: expected null to be 'true'
     Test Files  1 failed (1)
          Tests  3 failed | 12 passed (15)

### After

    $ npx vitest run packages/lexical-html/src/__tests__/unit/LineBreakRoundTrip.test.ts
     Test Files  1 passed (1)
          Tests  15 passed (15)

Both importers are independently covered, confirmed by mutation testing:
breaking only `coreImportRules`' `LineBreakRule` fails exactly the four
`$generateNodesFromDOMViaExtension` cases, and breaking only `LineBreakNode`'s
`$config()` `importDOM` fails exactly the four `$generateNodesFromDOM` cases.
@etrepum etrepum changed the title [lexical][lexical-html] Bug Fix: gate trailing <br> import drop on managed line breaks [lexical][lexical-html] Bug Fix: emit a terminating <br> so a trailing line break survives HTML export Aug 31, 2026
@levensta

Copy link
Copy Markdown
Contributor

Will this be included in the 0.50 release? That would be great

@etrepum
etrepum marked this pull request as ready for review August 31, 2026 19:00
@etrepum
etrepum added this pull request to the merge queue Aug 31, 2026
Merged via the queue into meta:main with commit 76a22dc Aug 31, 2026
46 checks passed
@etrepum etrepum mentioned this pull request Sep 2, 2026
zurfyx added a commit that referenced this pull request Oct 15, 2026
…havior changes and deprecations into CHANGELOG.md for v0.23 to v0.52, add an Upgrading page

## Description

Depends on the changesets tooling in #9357.

Past versions in CHANGELOG.md only list commits, so someone upgrading from
an older version cannot find what broke, or how to migrate, without reading
every GitHub release. Future versions get curated sections from changesets;
this gives v0.23.0 to v0.52.0 the same sections.

- Every version from v0.23.0 to v0.52.0 now starts with `### Breaking
  changes` (35 entries), `### Behavior changes` (43) and `### Deprecations`
  (29), each with packages and a PR link. The existing lines are kept,
  unchanged, under `### All changes` (the diff only adds lines).
- Rule, stated in the preamble: a breaking change needs a code change (an
  API removed or renamed, a type that no longer checks, a call that now
  throws) and has `Detect:` and `Migration:`. A behavior change keeps
  building but behaves or renders differently and has `Verify:`. The entries
  come from a verified inventory of those releases, which marked each change
  as manual, mechanical, or runtime-only ("no type or build error points at
  it"). Runtime-only entries are behavior changes, except #7341 (now throws)
  and #8603 (a signature change), which stay breaking.
- v0.50.0: the items its release notes list as "Behavior Changes to Watch"
  (#8765, #8908, #8884, #9059, #9061, #8940, #8283) are behavior changes;
  the listener return-type tightening (#8990), the new invariants (#6483)
  and the two items the release called breaking (#8938, #8995) stay
  breaking. Checked against the v0.50.0 release notes.
- Added the v0.42.0 removal of `@lexical/react/LexicalContextMenuPlugin`
  (#8199; present in the v0.41.0 tag, absent in v0.42.0).
- Deprecations come from a pass over every `@deprecated` tag added between
  consecutive tags v0.22.0 to v0.52.0, each checked against the previous tag
  and attributed with `git log -S`. Each has `Replacement:` and `Removal:`:
  the version that removed it, "no earlier than v0.53.0" for the ones #9316
  removes after v0.52.0, otherwise "not scheduled". Skipped: tags that only
  moved (`trimTextContentFromAnchor`, deprecated before v0.23.0) or restated
  earlier ones (v0.46.0 `HorizontalRulePlugin`, v0.51.0 `getScrollParent`),
  and the v0.47.0 `applyFormatToDom` deprecation that v0.48.0 reversed.
- Entries that mixed a breaking change and a deprecation are split with no
  double counting (#7357, #8360, #8661); #8350 and #8662 only deprecated
  aliases, so they are listed under Deprecations alone.
- `docs/upgrading.md` ("Upgrading" in the sidebar) is a short page: upgrade
  all packages together, read CHANGELOG.md between your version and the
  target (also at `node_modules/lexical/CHANGELOG.md`) or print that range,
  and a copy-paste `AGENTS.md` snippet that points coding agents at the
  installed changelog. Nothing is installed automatically.
- The repository CHANGELOG.md test checks every backfilled entry: `Detect:`
  and `Migration:` on breaking changes, `Verify:` on behavior changes,
  `Replacement:` and a valid `Removal:` on deprecations, a PR link on all.

## Test plan

### Before

```
$ pnpm run changelog:range -- --from 0.49.0 --breaking
Note: v0.50.0, v0.51.0, v0.52.0 have no curated sections (the changelog only lists their commits), so --breaking cannot show what changed there. Run without --breaking to read them in full.
No breaking changes, behavior changes or deprecations recorded after 0.49.0.
```

### After

```
$ git diff --numstat --diff-algorithm=patience HEAD~1 -- CHANGELOG.md
1412	0	CHANGELOG.md

$ pnpm run changelog:range -- --from 0.49.0 --breaking | grep '^## \|^### '
## v0.50.0 (2026-09-02)
### Breaking changes
### Behavior changes
### Deprecations
## v0.51.0 (2026-09-17)
### Breaking changes
### Deprecations
## v0.52.0 (2026-09-27)
### Breaking changes
### Behavior changes
### Deprecations

$ pnpm run changelog:range -- --from 0.49.0 --to 0.50.0 --breaking --json   # (kind, [(pr, behavior)])
[('breaking', [(8938, False), (8995, False), (8990, False), (6483, False)]), ('behavior', [(8765, True), (8908, True), (8884, True), (9059, True), (9061, True), (8940, True), (8283, True)]), ('deprecation', [(8918, False)])]

$ pnpm run test-unit scripts/__tests__/unit/changelog.test.ts scripts/__tests__/unit/changesets.test.ts
      Tests  63 passed (63)

$ pnpm -C packages/lexical-website run docusaurus build
[SUCCESS] Generated static files in "build".
```
zurfyx added a commit that referenced this pull request Oct 15, 2026
…havior changes and deprecations into CHANGELOG.md for v0.23 to v0.52, add an Upgrading page

## Description

Depends on the changesets tooling in #9357.

Past versions in CHANGELOG.md only list commits, so someone upgrading from
an older version cannot find what broke, or how to migrate, without reading
every GitHub release. Future versions get curated sections from changesets;
this gives v0.23.0 to v0.52.0 the same sections.

- Every version from v0.23.0 to v0.52.0 now starts with `### Breaking
  changes` (35 entries), `### Behavior changes` (43) and `### Deprecations`
  (29), each with packages and a PR link. The existing lines are kept,
  unchanged, under `### All changes` (the diff only adds lines).
- Rule, stated in the preamble: a breaking change needs a code change (an
  API removed or renamed, a type that no longer checks, a call that now
  throws) and has `Detect:` and `Migration:`. A behavior change keeps
  building but behaves or renders differently and has `Verify:`. The entries
  come from a verified inventory of those releases, which marked each change
  as manual, mechanical, or runtime-only ("no type or build error points at
  it"). Runtime-only entries are behavior changes, except #7341 (now throws)
  and #8603 (a signature change), which stay breaking.
- v0.50.0: the items its release notes list as "Behavior Changes to Watch"
  (#8765, #8908, #8884, #9059, #9061, #8940, #8283) are behavior changes;
  the listener return-type tightening (#8990), the new invariants (#6483)
  and the two items the release called breaking (#8938, #8995) stay
  breaking. Checked against the v0.50.0 release notes.
- Added the v0.42.0 removal of `@lexical/react/LexicalContextMenuPlugin`
  (#8199; present in the v0.41.0 tag, absent in v0.42.0).
- Deprecations come from a pass over every `@deprecated` tag added between
  consecutive tags v0.22.0 to v0.52.0, each checked against the previous tag
  and attributed with `git log -S`. Each has `Replacement:` and `Removal:`:
  the version that removed it, "no earlier than v0.53.0" for the ones #9316
  removes after v0.52.0, otherwise "not scheduled". Skipped: tags that only
  moved (`trimTextContentFromAnchor`, deprecated before v0.23.0) or restated
  earlier ones (v0.46.0 `HorizontalRulePlugin`, v0.51.0 `getScrollParent`),
  and the v0.47.0 `applyFormatToDom` deprecation that v0.48.0 reversed.
- Entries that mixed a breaking change and a deprecation are split with no
  double counting (#7357, #8360, #8661); #8350 and #8662 only deprecated
  aliases, so they are listed under Deprecations alone.
- `docs/upgrading.md` ("Upgrading" in the sidebar) is a short page: upgrade
  all packages together, read CHANGELOG.md between your version and the
  target (also at `node_modules/lexical/CHANGELOG.md`) or print that range,
  and a copy-paste `AGENTS.md` snippet that points coding agents at the
  installed changelog. Nothing is installed automatically.
- The repository CHANGELOG.md test checks every backfilled entry: `Detect:`
  and `Migration:` on breaking changes, `Verify:` on behavior changes,
  `Replacement:` and a valid `Removal:` on deprecations, a PR link on all.

## Test plan

### Before

```
$ pnpm run changelog:range -- --from 0.49.0 --breaking
Note: v0.50.0, v0.51.0, v0.52.0 have no curated sections (the changelog only lists their commits), so --breaking cannot show what changed there. Run without --breaking to read them in full.
No breaking changes, behavior changes or deprecations recorded after 0.49.0.
```

### After

```
$ git diff --numstat --diff-algorithm=patience HEAD~1 -- CHANGELOG.md
1412	0	CHANGELOG.md

$ pnpm run changelog:range -- --from 0.49.0 --breaking | grep '^## \|^### '
## v0.50.0 (2026-09-02)
### Breaking changes
### Behavior changes
### Deprecations
## v0.51.0 (2026-09-17)
### Breaking changes
### Deprecations
## v0.52.0 (2026-09-27)
### Breaking changes
### Behavior changes
### Deprecations

$ pnpm run changelog:range -- --from 0.49.0 --to 0.50.0 --breaking --json   # (kind, [(pr, behavior)])
[('breaking', [(8938, False), (8995, False), (8990, False), (6483, False)]), ('behavior', [(8765, True), (8908, True), (8884, True), (9059, True), (9061, True), (8940, True), (8283, True)]), ('deprecation', [(8918, False)])]

$ pnpm run test-unit scripts/__tests__/unit/changelog.test.ts scripts/__tests__/unit/changesets.test.ts
      Tests  63 passed (63)

$ pnpm -C packages/lexical-website run docusaurus build
[SUCCESS] Generated static files in "build".
```
zurfyx added a commit that referenced this pull request Oct 28, 2026
…havior changes and deprecations into CHANGELOG.md for v0.23 to v0.52, add an Upgrading page

Depends on the changesets tooling in #9357.

Past versions in CHANGELOG.md only list commits, so someone upgrading from
an older version cannot find what broke, or how to migrate, without reading
every GitHub release. Future versions get curated sections from changesets;
this gives v0.23.0 to v0.52.0 the same sections.

- Every version from v0.23.0 to v0.52.0 now starts with `### Breaking
  changes` (35 entries), `### Behavior changes` (43) and `### Deprecations`
  (29), each with packages and a PR link. The existing lines are kept,
  unchanged, under `### All changes` (the diff only adds lines).
- Rule, stated in the preamble: a breaking change needs a code change (an
  API removed or renamed, a type that no longer checks, a call that now
  throws) and has `Detect:` and `Migration:`. A behavior change keeps
  building but behaves or renders differently and has `Verify:`. The entries
  come from a verified inventory of those releases, which marked each change
  as manual, mechanical, or runtime-only ("no type or build error points at
  it"). Runtime-only entries are behavior changes, except #7341 (now throws)
  and #8603 (a signature change), which stay breaking.
- v0.50.0: the items its release notes list as "Behavior Changes to Watch"
  (#8765, #8908, #8884, #9059, #9061, #8940, #8283) are behavior changes;
  the listener return-type tightening (#8990), the new invariants (#6483)
  and the two items the release called breaking (#8938, #8995) stay
  breaking. Checked against the v0.50.0 release notes.
- Added the v0.42.0 removal of `@lexical/react/LexicalContextMenuPlugin`
  (#8199; present in the v0.41.0 tag, absent in v0.42.0).
- Deprecations come from a pass over every `@deprecated` tag added between
  consecutive tags v0.22.0 to v0.52.0, each checked against the previous tag
  and attributed with `git log -S`. Each has `Replacement:` and `Removal:`:
  the version that removed it, "no earlier than v0.53.0" for the ones #9316
  removes after v0.52.0, otherwise "not scheduled". Skipped: tags that only
  moved (`trimTextContentFromAnchor`, deprecated before v0.23.0) or restated
  earlier ones (v0.46.0 `HorizontalRulePlugin`, v0.51.0 `getScrollParent`),
  and the v0.47.0 `applyFormatToDom` deprecation that v0.48.0 reversed.
- Entries that mixed a breaking change and a deprecation are split with no
  double counting (#7357, #8360, #8661); #8350 and #8662 only deprecated
  aliases, so they are listed under Deprecations alone.
- `docs/upgrading.md` ("Upgrading" in the sidebar) is a short page: upgrade
  all packages together, read CHANGELOG.md between your version and the
  target (also at `node_modules/lexical/CHANGELOG.md`) or print that range,
  and a copy-paste `AGENTS.md` snippet that points coding agents at the
  installed changelog. Nothing is installed automatically.
- The repository CHANGELOG.md test checks every backfilled entry: `Detect:`
  and `Migration:` on breaking changes, `Verify:` on behavior changes,
  `Replacement:` and a valid `Removal:` on deprecations, a PR link on all.

```
$ pnpm run changelog:range -- --from 0.49.0 --breaking
Note: v0.50.0, v0.51.0, v0.52.0 have no curated sections (the changelog only lists their commits), so --breaking cannot show what changed there. Run without --breaking to read them in full.
No breaking changes, behavior changes or deprecations recorded after 0.49.0.
```

```
$ git diff --numstat --diff-algorithm=patience HEAD~1 -- CHANGELOG.md
1412	0	CHANGELOG.md

$ pnpm run changelog:range -- --from 0.49.0 --breaking | grep '^## \|^### '

$ pnpm run changelog:range -- --from 0.49.0 --to 0.50.0 --breaking --json   # (kind, [(pr, behavior)])
[('breaking', [(8938, False), (8995, False), (8990, False), (6483, False)]), ('behavior', [(8765, True), (8908, True), (8884, True), (9059, True), (9061, True), (8940, True), (8283, True)]), ('deprecation', [(8918, False)])]

$ pnpm run test-unit scripts/__tests__/unit/changelog.test.ts scripts/__tests__/unit/changesets.test.ts
      Tests  63 passed (63)

$ pnpm -C packages/lexical-website run docusaurus build
[SUCCESS] Generated static files in "build".
```

This branch was successfully deployed

2 active deployments
Preview – lexical — 31a50898 Deployed Aug 31, 2026 by vercel[bot]
Preview – lexical-playground — 31a50898 Deployed Aug 31, 2026 by vercel[bot]
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. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants