Repository navigation
[lexical-markdown] Bug Fix: Fix nested mixed-type list structure during markdown import - #8283
Merged
etrepum merged 42 commits intoSep 2, 2026
Conversation
…ng markdown import
achaljhawar
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7,
potatowagon,
takuyakanbr and
zurfyx
as code owners
April 5, 2026 05:06
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
reviewed
Apr 21, 2026
etrepum
marked this pull request as draft
April 22, 2026 04:20
…line
## Description
The levels a list leaves open were closed by any block that was not a list,
and a blank line is a block: it arrives as an empty paragraph and only gets
dropped once the import is over. So a blank line decided which of two indent
rules the line after it was read by. `1. First\n - detail` took the sublist
and `1. First\n\n - detail` did not, though a blank line before a sublist
only makes the list loose.
Reading one form by columns and the other by the fixed step also left an
indent that does not survive its own export: `- a\n\n - b` was read as
two levels by `getIndent`, exported as `- a\n - b` with the blank line
dropped, and read back as one level by the columns.
A blank line no longer closes the levels. They stay open while the nearest
block that is not one is still the list itself, so a paragraph or a code fence
closes them whether or not blank lines surround it.
## Test plan
`pnpm exec vitest run packages/lexical-markdown packages/lexical-list`
### Before
```
FAIL Markdown > can import "- a\n\n - b"
FAIL Markdown > can import "1. First\n\n - detail"
FAIL Loose list indents round trip > re-imports its own export of "- a\n\n - b" unchanged
Test Files 1 failed | 10 passed (11)
Tests 3 failed | 618 passed (621)
```
The round trip reads:
```
- Expected '- a\n - b'
+ Received '- a\n - b'
```
### After
```
Test Files 11 passed (11)
Tests 621 passed (621)
```
Tight and loose now agree, and each is its own fixed point:
```
'- a\n - b' -> '- a\n - b'
'- a\n\n - b' -> '- a\n - b'
'- a\n - b' -> '- a\n - b'
'- a\n\n - b' -> '- a\n - b'
'1. First\n - detail' -> '1. First\n - detail'
'1. First\n\n - detail' -> '1. First\n\n - detail'
```
while a block of another kind still closes them, blank lines or not:
```
'- a\n\ntext\n\n - b' -> '- a\n\ntext\n\n- b'
'- a\n\n```\ncode\n```\n\n - b' -> '- a\n\n```\ncode\n```\n\n- b'
```
`pnpm run test-unit`
```
Test Files 227 passed (227)
Tests 5003 passed | 1 skipped (5004)
```
`pnpm run ci-check`
```
No errors!
```
Playwright, against the playground dev server:
```
pnpm exec playwright test --project=chromium \
packages/lexical-playground/__tests__/e2e/Markdown.spec.mjs \
packages/lexical-playground/__tests__/e2e/List.spec.mjs \
packages/lexical-playground/__tests__/e2e/CheckList.spec.mjs
89 passed (6.7m)
```
…1n2lz' into fix/nested-mixed-type-list-markdown-import
…asures against
## Description
Review follow-ups, all reproduced before fixing.
The blank-line fix taught the indent measurement to look across blank lines,
but not the placement: the line was measured against the list above the blanks
and then placed relative to its immediate sibling, the blank paragraph. A
loose same-type sublist only looked right because the `ListNode` transform
later merged the two lists it left behind — which `$generateNodesFromMarkdown-
String` never runs, so it returned a split list — and a loose type-changing
sublist (`- a\n\n 1. b`) had no such rescue: it became a detached list nested
inside itself. The line is now placed into the same block it is measured
against, so both land inside the item above them, joined. The two placement
branches this touches had become identical and are merged. An import that
preserves new lines keeps blank paragraphs as content, so there a blank line
still closes the list like any block.
The typed number of an indented ordered item was written onto the list it was
inserted into before `setIndent` moved it out: typing ` 1. z` above an
existing `1. y` list renumbered that list to start at 1 while `z` went into a
sublist. The start is only taken when the item stays where it landed.
`[X]` imported as unchecked: `CHECK_LIST_REGEX` matches case-insensitively,
but the checked test compared against lowercase `x` only.
A tab after a list marker was measured as one column, though it advances to
the next tab stop: `-\ta` opens its content at column four, so a two-space
`- b` under it is a sibling, not a sublist. The content column is now read
from where the matched marker ends with tabs expanded, which also removes the
special case for numbered markers.
## Test plan
`pnpm exec vitest run packages/lexical-markdown packages/lexical-list`
### Before
```
FAIL Markdown > can import "1. First\n\n - detail"
FAIL List marker details > reads an uppercase [X] as checked, as the /i on its regex intends
FAIL List marker details > expands a tab after the marker when measuring the content column
FAIL List marker details > keeps a typed start number out of a list the item only passes through
FAIL Loose sublists > nests a loose type-changing sublist into the item above it
FAIL Loose sublists > returns one joined list from $generateNodesFromMarkdownString
Test Files 1 failed | 10 passed (11)
Tests 6 failed | 620 passed (626)
```
The loose type-changing case read, before:
```
'- a\n\n 1. b' -> <ul><li>a</li></ul><ol><li><ol><li>b</li></ol></li></ol>
```
and now:
```
'- a\n\n 1. b' -> <ul><li>a<ol><li>b</li></ol></li></ul>
```
### After
```
Test Files 11 passed (11)
Tests 626 passed (626)
```
`pnpm run test-unit`
```
Test Files 227 passed (227)
Tests 5008 passed | 1 skipped (5009)
```
`pnpm run ci-check`
```
No errors!
```
Playwright, against the playground dev server:
```
pnpm exec playwright test --project=chromium \
packages/lexical-playground/__tests__/e2e/Markdown.spec.mjs \
packages/lexical-playground/__tests__/e2e/List.spec.mjs \
packages/lexical-playground/__tests__/e2e/CheckList.spec.mjs
89 passed (6.6m)
```
## Description
An error thrown inside `editor.update` or `editor.read` is routed to the
editor's `onError` handler rather than rethrown, and `createHeadlessEditor`
defaults that handler to `console.error`. So a failed assertion inside an
update logged and passed — which is how a regression test on this branch
managed to pass against the code it was written to catch, until it was
restructured to assert outside the update.
Every editor in this file now goes through one `createTestEditor` helper that
throws from `onError`, the way `buildEditorFromExtensions` does by default,
and defaults to the node set the file uses throughout — which also replaces
the five identical per-describe copies of that helper. All 495 tests still
pass with errors propagating, so none of the existing in-update assertions
were hiding a failure.
## Test plan
`pnpm exec vitest run packages/lexical-markdown packages/lexical-list`
```
Test Files 11 passed (11)
Tests 626 passed (626)
```
`pnpm run test-unit`
```
Test Files 227 passed (227)
Tests 5008 passed | 1 skipped (5009)
```
`tsc --noEmit`, `eslint`, `prettier --check` on the file: clean. No source
files changed.
…1n2lz' into fix/nested-mixed-type-list-markdown-import
etrepum
previously approved these changes
Sep 2, 2026
…rkdown import
## Description
"link destination whitespace does not backtrack > reads a run of tabs" has
been failing with a stack overflow the whole time it has existed — the crash
was routed to the editor's default `onError` and logged, so the test passed
vacuously until the error handlers in this file were made to throw.
Two overflows, one pattern: an argument or element per node in a document
whose size nothing bounds.
`$normalizeMarkdownTextNode` spread one offset per tab boundary into
`splitText(...)`, so a pasted line with two hundred thousand tabs overflowed
the call stack before a single node was made. It now builds the replacement
text and tab nodes directly — which also skips the detour of splitting into
single-character nodes only to replace half of them — and returns early for a
`TabNode`, which is already a tab and would only be destroyed and recreated.
`ElementNode.getAllTextNodes` then collected the two hundred thousand nodes
the import now produces with `push(...children)`, which is the same overflow
one call later. It appends in a loop.
Every remaining `splitText` caller in the repository passes one or two fixed
offsets, so no array-taking variant of it is needed for this.
## Test plan
The previously-vacuous test is the regression test; it now runs the code it
was written to time and passes within its 5s limit.
`pnpm run test-unit`
```
Test Files 323 passed (323)
Tests 6029 passed | 1 skipped (6030)
```
`pnpm run ci-check`
```
No errors!
```
…1n2lz' into fix/nested-mixed-type-list-markdown-import
…ration
## Description
`$normalizeMarkdownTextNode` walked its replacement nodes in with one
`insertAfter` per node and a trailing `remove()`. `splice` is the primitive
those are built on, so the walker and its moving cursor are replaced with one
call that swaps the text node for the whole replacement list — and it takes
the list as an array, so nothing scales with the node count but the list
itself.
## Test plan
`pnpm exec vitest run packages/lexical-markdown`
```
Test Files 7 passed (7)
Tests 631 passed (631)
```
including "reads a run of tabs" (200,000 tabs) within its 5s limit.
`pnpm run test-unit`
```
Test Files 323 passed (323)
Tests 6029 passed | 1 skipped (6030)
```
etrepum
approved these changes
Sep 2, 2026
Merged
This was referenced Sep 9, 2026
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
Importing markdown with nested lists of different types (e.g. bullet containing ordered) flattened them into separate top-level lists.
listReplaceonly merged items into an adjacent list when types matched, so indented items of a different type couldn't merge. Fixed by allowing the merge when indented regardless of type, then correcting the nested list type aftersetIndent().Closes #7938
Before
Lexical.Playground.12.mp4
After
Lexical.Playground.13.mp4