Skip to content

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

Merged
etrepum merged 1 commit into
meta:mainfrom
etrepum:claude/elegant-clarke-brh0km
Jun 18, 2026
Merged

etrepum merged 1 commit into
meta:mainfrom
etrepum:claude/elegant-clarke-brh0km

Conversation

@etrepum

@etrepum etrepum commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LhtHEDfkNQUf5HPv9cqLXa
@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 18, 2026
@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 Ready Ready Preview, Comment Jun 18, 2026 3:38pm
lexical-playground Ready Ready Preview, Comment Jun 18, 2026 3:38pm

Request Review

@potatowagon potatowagon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed by Navi (Tater Thoughts Bobblehead) on behalf of @potatowagon.

Assessment: LGTM ✅

Summary: Replaces the third-party react-error-boundary dependency with a self-contained class-component ErrorBoundary inside @lexical/react/LexicalErrorBoundary. Also adds an optional fallback prop (defaults to the existing red-bordered "An error was thrown" div; pass null for silent failure). Playground usages migrated from react-error-boundary → the new built-in.

What I checked:

  1. Correctness of the class component: getDerivedStateFromError returns {hasError: true} — standard pattern. componentDidCatch coerces unknown errors to Error with {cause} — same logic previously in the function wrapper, now centralized in the class.
  2. Backward compatibility: The exported LexicalErrorBoundary keeps the same function-component signature. onError now receives (Error, ErrorInfo) directly — callers that passed (error: Error) => void still work since the second arg is just ignored. The fallback prop is optional with a sensible default.
  3. www compat: No removed/renamed exports. LexicalErrorBoundary name + import path unchanged. www consumers of RichTextPlugin/PlainTextPlugin pass ErrorBoundary={LexicalErrorBoundary} — that contract is preserved. The react-error-boundary removal from the bundle is a win (tree-shaking improvement, fewer external deps).
  4. Build config: scripts/build.mjs no longer lists react-error-boundary in thirdPartyExternals — correct since it is no longer a dependency.
  5. Flow types: Updated to add optional fallback?: React.Node — matches the TS type.
  6. Edge cases: Considered whether hasError state resets on children change — it does not (no resetKeys equivalent). This matches the previous behavior since callers never used resetKeys. If needed, that can be added later.
  7. Playground migration: Both EquationComponent.tsx and KatexEquationAlterer.tsx switch to LexicalErrorBoundary with fallback={null} and simplified onError (no more manual coercion since the class handles it).

CI status: Core tests (unit 22.x+24.x, browser all platforms, integrity), integration, and majority of e2e matrix all green. A few e2e runners still pending (linux firefox, collab-mac webkit, prod) — no failures.

Verdict: Clean removal of a third-party dependency in favor of a minimal self-contained implementation. Reduces bundle size, eliminates supply-chain surface. No behavioral regressions. Ready to approve once the remaining e2e checks go green.

@etrepum
etrepum added this pull request to the merge queue Jun 18, 2026
Merged via the queue into meta:main with commit dbb2729 Jun 18, 2026
52 checks passed
@etrepum etrepum mentioned this pull request Jun 25, 2026

This branch was successfully deployed

2 active deployments
Preview – lexical — 97f2f096 Deployed Jun 18, 2026 by vercel[bot]
Preview – lexical-playground — 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

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