fix: move providers inside ErrorBoundary to prevent crash loop#4783
Open
fix: move providers inside ErrorBoundary to prevent crash loop#4783
Conversation
Move ExploreStateProvider, DataDictionaryStateProvider, and FileManifestStateProvider inside the ErrorBoundary in _app.tsx. Previously these providers sat above the ErrorBoundary. When a provider crashed (e.g. ExploreStateProvider's reducer throwing on a malformed filter URL param), the error bypassed the ErrorBoundary entirely and bubbled up to Next.js's built-in error handling, which attempted to recover by re-rendering the page — triggering the same crash in an infinite loop. With the providers inside the ErrorBoundary, any error from their reducers, hooks, or child components is caught and rendered as the Error fallback page. The header and footer remain visible (they are intentionally outside the boundary) so the user can still navigate away. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
47ac5e7 to
571d693
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Moves key state providers under the app-level ErrorBoundary so reducer/hook crashes (e.g., invalid filter URL params) are caught by the fallback UI instead of triggering Next.js re-render recovery loops.
Changes:
- Reordered component tree in
_app.tsxto placeExploreStateProvider,DataDictionaryStateProvider, andFileManifestStateProviderinside theErrorBoundary. - Kept
Header/Footeroutside the boundary so navigation remains available on the error fallback page.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
Fixes the infinite retry loop when a filter query parameter contains an invalid value (#4776).
Root Cause
ExploreStateProvider,DataDictionaryStateProvider, andFileManifestStateProviderwere positioned above theErrorBoundaryin the component tree. WhenExploreStateProvider's reducer crashed (e.g.JSON.parseon a malformed filter URL param, or accessing.lengthon a wrong-shape filter object), the error bypassed theErrorBoundaryentirely and bubbled up to Next.js's built-in error handling. Next.js attempted to recover by re-rendering the page, which hit the same crash again — creating an infinite loop.Fix
Move the three providers inside the
ErrorBoundary:Now any error from the providers' reducers, hooks, or child components is caught by the
ErrorBoundaryand renders the Error fallback page. The Header and Footer remain outside the boundary so the user can still navigate away from the error page.Why this works
The Error fallback component does not consume
ExploreState,DataDictionaryState, orFileManifestState— it only needs the error object, a reset callback, and the root path (from app config). There is no reason these providers need to be above the boundary.Closes #4776
Test plan
Tested all three invalid filter param cases:
?filter=%5B%7B%22categoryKey...) → shows error page?filter=[{"facetName":"bogus","terms":["invalid"]}]) → shows error page?filter=[{"categoryKey":"bogus","value":["invalid"]}]) → shows API 400 error page🤖 Generated with Claude Code