Skip to content

fix(ErrorBoundary): reset when the thrown value is null - #247

Merged
bvaughn merged 1 commit into
bvaughn:mainfrom
hovelopin:fix/reset-thrown-value-null
Aug 30, 2026
Merged

fix(ErrorBoundary): reset when the thrown value is null#247
bvaughn merged 1 commit into
bvaughn:mainfrom
hovelopin:fix/reset-thrown-value-null

Conversation

@hovelopin

Copy link
Copy Markdown
Contributor

What

ErrorBoundary can't be reset — neither via resetErrorBoundary() nor via resetKeys — when the thrown value is null. Once the fallback is shown it stays there.

Why

Both reset paths check error !== null to decide whether the boundary is currently active:

// resetErrorBoundary
if (error !== null) { ... }

// componentDidUpdate
if (didCatch && prevState.error !== null && hasArrayChanged(...)) { ... }

When null is thrown, getDerivedStateFromError(null) produces { didCatch: true, error: null }, so both guards fail and onReset / setState(initialState) never run. useErrorBoundary().showBoundary(null) followed by resetBoundary() hits the same path.

Only null is affected — the comparison is strict, so undefined, 0, "" etc. reset correctly.

How

  • Gate both paths on didCatch (and prevState.didCatch) instead of error !== null. The existing "skip the first componentDidUpdate after an error" behavior is preserved since prevState.didCatch is false on that call.
  • Add two tests to the "thrown values" block covering reset via prop and via resetKeys after throwing null. Both fail on main and pass with this change.

The existing "should support thrown null or undefined values" test only covered rendering and onError, which is why this slipped through.

@vercel

vercel Bot commented Aug 29, 2026

Copy link
Copy Markdown

@hovelopin is attempting to deploy a commit to the Brian Vaughn's projects Team on Vercel.

A member of the Team first needs to authorize it.

@bvaughn bvaughn left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

👍🏼

@bvaughn
bvaughn merged commit 82dfebf into bvaughn:main Aug 30, 2026
1 check failed
@bvaughn

bvaughn commented Aug 30, 2026

Copy link
Copy Markdown
Owner

react-error-boundary@6.1.4

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