Repository navigation
[lexical-react][lexical-playground] Refactor: Replace react-error-boundary with a self-contained LexicalErrorBoundary - #8720
Conversation
…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
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
potatowagon
left a comment
There was a problem hiding this comment.
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:
- Correctness of the class component:
getDerivedStateFromErrorreturns{hasError: true}— standard pattern.componentDidCatchcoerces unknown errors toErrorwith{cause}— same logic previously in the function wrapper, now centralized in the class. - Backward compatibility: The exported
LexicalErrorBoundarykeeps the same function-component signature.onErrornow receives(Error, ErrorInfo)directly — callers that passed(error: Error) => voidstill work since the second arg is just ignored. Thefallbackprop is optional with a sensible default. - www compat: No removed/renamed exports.
LexicalErrorBoundaryname + import path unchanged. www consumers ofRichTextPlugin/PlainTextPluginpassErrorBoundary={LexicalErrorBoundary}— that contract is preserved. Thereact-error-boundaryremoval from the bundle is a win (tree-shaking improvement, fewer external deps). - Build config:
scripts/build.mjsno longer listsreact-error-boundaryin thirdPartyExternals — correct since it is no longer a dependency. - Flow types: Updated to add optional
fallback?: React.Node— matches the TS type. - Edge cases: Considered whether
hasErrorstate resets on children change — it does not (noresetKeysequivalent). This matches the previous behavior since callers never usedresetKeys. If needed, that can be added later. - Playground migration: Both
EquationComponent.tsxandKatexEquationAlterer.tsxswitch toLexicalErrorBoundarywithfallback={null}and simplifiedonError(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.
Description
react-error-boundarywas a trivial dependency.@lexical/reactand 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
LexicalErrorBoundaryand drops the dependency:LexicalErrorBoundaryno longer wrapsreact-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 optionalfallbackprop. Withfallbackomitted it shows the existing default message; passfallback={null}to render nothing. Its public type is otherwise unchanged, so it remains usable as theErrorBoundaryprop ofRichTextPlugin/PlainTextPlugin. Keeping it a function component preserves the prop variance that contract relies on — as a class component the two-argumentonErrorwould not be assignable to the single-argument boundary prop.EquationComponent,KatexEquationAlterer) now useLexicalErrorBoundarydirectly withfallback={null}instead of importingErrorBoundaryfromreact-error-boundary. The error coercion they did inline now lives inLexicalErrorBoundary, so theironErrorsimplifies toeditor._onError.react-error-boundaryis removed from bothpackage.jsonfiles, thescripts/build.mjsexternals 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-boundarysupplied<ErrorBoundary>;LexicalErrorBoundarywrapped it, and the playground imported it directly.After
LexicalErrorBoundaryis self-contained with an optionalfallbackprop and is used directly everywhere. All green locally:pnpm run tsc(whole repo)pnpm run flowpnpm run lintandpnpm run prettierLexicalErrorBoundary:PlainRichTextPlugin,LexicalNestedComposer,LexicalCollaborationPluginscripts/__tests__/unit/build.test.tspackage.json / exports audits