Skip to content

[lexical-react][lexical-playground] Refactor: Replace react-error-boundary with a self-contained LexicalErrorBoundary - #13

Closed
etrepum wants to merge 1 commit into
mainfrom
claude/elegant-clarke-brh0km
Closed

etrepum wants to merge 1 commit into
mainfrom
claude/elegant-clarke-brh0km

Conversation

@etrepum

@etrepum etrepum commented Jun 18, 2026

Copy link
Copy Markdown
Owner

Description

react-error-boundary was a trivial dependency. @lexical/react and the playground only used its <ErrorBoundary fallback onError> variant, so it was not worth taking on a third-party package — dependencies are liabilities.

This folds that small amount of behavior into LexicalErrorBoundary and drops the dependency:

  • LexicalErrorBoundary no longer wraps react-error-boundary. It is now a self-contained boundary (a function component over a small private class, since React error boundaries must be class components) and gains an optional fallback prop. With fallback omitted it shows the existing default message; pass fallback={null} to render nothing. Its public type is otherwise unchanged, so it remains usable as the ErrorBoundary prop of RichTextPlugin/PlainTextPlugin. Keeping it a function component preserves the prop variance that contract relies on — as a class component the two-argument onError would not be assignable to the single-argument boundary prop.
  • The playground equation components (EquationComponent, KatexEquationAlterer) now use LexicalErrorBoundary directly with fallback={null} instead of importing ErrorBoundary from react-error-boundary. The error coercion they did inline now lives in LexicalErrorBoundary, so their onError simplifies to editor._onError.
  • react-error-boundary is removed from both package.json files, the scripts/build.mjs externals list, and the lockfile.

No behavior change is intended for existing call sites; the reset features of react-error-boundary (resetKeys, fallbackRender, ...) were unused and are intentionally not reimplemented.

Test plan

A dependency-removal refactor with no intended behavior change, so there is nothing to compare visually.

Before

react-error-boundary supplied <ErrorBoundary>; LexicalErrorBoundary wrapped it, and the playground imported it directly.

After

LexicalErrorBoundary is self-contained with an optional fallback prop and is used directly everywhere. All green locally:

  • pnpm run tsc (whole repo)
  • pnpm run flow
  • pnpm run lint and pnpm run prettier
  • Unit tests that mount LexicalErrorBoundary: PlainRichTextPlugin, LexicalNestedComposer, LexicalCollaborationPlugin
  • scripts/__tests__/unit/build.test.ts package.json / exports audits

…ndary with a self-contained LexicalErrorBoundary

## Description

`react-error-boundary` was a trivial dependency. `@lexical/react` and the
playground only used its `<ErrorBoundary fallback onError>` variant, so it
was not worth taking on a third-party package — dependencies are liabilities.

This folds that small amount of behavior into `LexicalErrorBoundary` and drops
the dependency:

- `LexicalErrorBoundary` no longer wraps `react-error-boundary`. It is now a
  self-contained boundary (a function component over a small private class,
  since React error boundaries must be class components) and gains an optional
  `fallback` prop. With `fallback` omitted it shows the existing default
  message; pass `fallback={null}` to render nothing. Its public type is
  otherwise unchanged, so it remains usable as the `ErrorBoundary` prop of
  `RichTextPlugin`/`PlainTextPlugin`. Keeping it a function component preserves
  the prop variance that contract relies on — as a class component the
  two-argument `onError` would not be assignable to the single-argument
  boundary prop.
- The playground equation components (`EquationComponent`,
  `KatexEquationAlterer`) now use `LexicalErrorBoundary` directly with
  `fallback={null}` instead of importing `ErrorBoundary` from
  `react-error-boundary`. The error coercion they did inline now lives in
  `LexicalErrorBoundary`, so their `onError` simplifies to `editor._onError`.
- `react-error-boundary` is removed from both `package.json` files, the
  `scripts/build.mjs` externals list, and the lockfile.

No behavior change is intended for existing call sites; the reset features of
`react-error-boundary` (`resetKeys`, `fallbackRender`, ...) were unused and are
intentionally not reimplemented.

## Test plan

A dependency-removal refactor with no intended behavior change, so there is
nothing to compare visually.

### Before

`react-error-boundary` supplied `<ErrorBoundary>`; `LexicalErrorBoundary`
wrapped it, and the playground imported it directly.

### After

`LexicalErrorBoundary` is self-contained with an optional `fallback` prop and
is used directly everywhere. All green locally:

- `pnpm run tsc` (whole repo)
- `pnpm run flow`
- `pnpm run lint` and `pnpm run prettier`
- Unit tests that mount `LexicalErrorBoundary`: `PlainRichTextPlugin`,
  `LexicalNestedComposer`, `LexicalCollaborationPlugin`
- `scripts/__tests__/unit/build.test.ts` package.json / exports audits

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LhtHEDfkNQUf5HPv9cqLXa
@vercel

vercel Bot commented Jun 18, 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 Jun 18, 2026 3:34pm

@etrepum etrepum closed this Jun 18, 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 21, 2026
…verb and directive attributes in a cell

## Description

Round 4 of the review of a cell's one-line JavaScript and TeX:

- An escaped pipe in a string or template (`"a\|b"`) was written as `\\x7c`, which reads as a backslash; the escape is now replaced whole.
- A TeX comment right after an earlier one's indentation, or after an escape (`\\%`), was kept or lost its control word's space. Comments are now found by reading escapes and control words as units.
- `\verb|x|` had its delimiters written as `\vert`; it now takes another delimiter its text lacks.
- A directive's attribute strings in a cell kept their line ends and pipes; they are written as references, which directives read, like JSX attributes. A carriage return is kept as `&#13;`.
- Blank lines in JSX text collapse to one space, as JSX does.

The tests now also read the exported cells back with MDX (micromark-extension-mdxjs and mdast-util-mdx, plus the directive extension, as dev dependencies) and check the row keeps one cell and the expressions, JSX attributes and directive attributes keep their values.

## Test plan

### Before

```
$ vitest run --project unit packages/lexical-mdast/src/__tests__/unit/MdastImportExport.test.ts
       × keeps {"type":"mdxFlowExpression","value":"\"a\\|b\\\\\" + `c\\|d`"} a block exports to in a cell on its row 10ms
       × keeps {"type":"math","value":"x%c\n  \\\\%d\ny\\beta%\n  \\alpha%\nb \\verb|x|"} a block exports to in a cell on its row 3ms
       × keeps {"type":"mdxFlowExpression","value":"<p>a\n\n  b</p>"} a block exports to in a cell on its row 2ms
         × "\"a\\|b\\\\\" + `c\\|d`" keeps its value 4ms
         × keeps the attributes and text of JSX 6ms
         × keeps the attributes of a directive 3ms
      Tests  6 failed | 196 passed (202)
```

### After

```
$ vitest run --project unit packages/lexical-mdast
 Test Files  7 passed (7)
      Tests  319 passed (319)
```

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
etrepum pushed a commit that referenced this pull request Oct 29, 2026
…g, add changeset

## Description

On top of the line-ending fix for link titles, `LINK.export` escaped the destination and the title with the same three steps written out twice: character references, the shape's own syntax characters, then line endings as `&#13;`/`&#10;`. They now go through one `escapeLinkPart(value, syntax)` helper, so the destination and title can't drift apart again, and the comment that explained line endings for the destination alone now covers both. Output is unchanged from the previous commit.

Also merges upstream main and adds the changeset for the title fix, with a `Verify:` paragraph since exported Markdown changes for titles that contain a line ending.

## Changeset

`.changeset/escape-line-endings-in-link-titles.md`: `[fix]` for `@lexical/markdown`, with `Verify:`.

## Test plan

### After

```
$ vitest run --project unit packages/lexical-markdown
 Test Files  9 passed (9)
      Tests  785 passed (785)
$ pnpm run check-changesets
Changeset check passed: 6 pending changeset(s) valid.
```

Co-Authored-By: Claude Opus 5.5 <[email protected]>
etrepum pushed a commit that referenced this pull request Oct 29, 2026
…g, add changeset

## Description

On top of the line-ending fix for link titles, `LINK.export` escaped the destination and the title with the same three steps written out twice: character references, the shape's own syntax characters, then line endings as `&#13;`/`&#10;`. They now go through one `escapeLinkPart(value, syntax)` helper, so the destination and title can't drift apart again, and the comment that explained line endings for the destination alone now covers both. Output is unchanged from the previous commit.

Also adds the changeset for the title fix, with a `Verify:` paragraph since exported Markdown changes for titles that contain a line ending.

## Changeset

`.changeset/escape-line-endings-in-link-titles.md`: `[fix]` for `@lexical/markdown`, with `Verify:`.

## Test plan

### After

```
$ vitest run --project unit packages/lexical-markdown
 Test Files  9 passed (9)
      Tests  785 passed (785)
$ pnpm run check-changesets
Changeset check passed: 6 pending changeset(s) valid.
```

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch was successfully deployed

1 active deployment
Preview — 97f2f096 Deployed Jun 18, 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