useClearResetErrorBoundary crashes entire app when useContext returns undefined (React 19.x) β Uncaught TypeError: reading 'clearReset' #12729
Describe the bug#
useClearResetErrorBoundary() crashes the entire application with an uncaught TypeError when useContext returns undefined for the reset-boundary context:
Uncaught TypeError: Cannot read properties of undefined (reading 'clearReset')
The value returned by useQueryErrorResetBoundary() is used unguarded in three places in errorBoundaryUtils.ts β errorResetBoundary.clearReset() in useClearResetErrorBoundary, and errorResetBoundary.isReset() in both ensurePreventErrorBoundaryRetry and getHasError. When the read returns undefined, the effect throws; and because this happens in a passive effect, error boundaries cannot catch it β React unmounts the entire component tree, so the user-facing result is the whole page going dead.
Under normal circumstances useContext cannot return undefined here: QueryErrorResetBoundaryContext has been created with a default value since v5.0.0, and our app renders no provider for it. However, under React 19.x we observe the read returning undefined under specific async interleavings β a React bug (introduced between React 18.3.1 and 19.0.0 per our bisect; the lazy context propagation machinery is the likely culprit, consistent with the open family issues on the React side: react#38040, react#38389). We are reporting that to React separately β this report asks react-query to guard these accesses, so that an unexpected context read degrades gracefully (skipping a retry-flag reset) instead of tearing down the host application.
Your minimal, reproducible example#
NA
Steps to reproduce#
We have not been able to reproduce this in a standalone minimal app. We tried: the same dependency versions, real network-level request blocking (genuine ERR_BLOCKED_BY_CLIENT rejections from an tracker blocker), randomized fetch latency, successes mixed with failures, retry: 1, dozens of query observers with rapid mount/unmount churn, plus background event-loop churn β none of that reproduces it standalone. The crash only occurs when runs inside its real host page (which loads several other scripts whose requests get blocked, producing event-loop congestion that reshuffles timing).
What reproduces it reliably in our app:
- Production build with
react@19.x+@tanstack/react-query@5.108.2,QueryClientProviderat root, no<QueryErrorResetBoundary>(relies on the context default), dozens ofuseQueryobservers,retry: 1, nothrowOnError/suspense - Loaded with an track blocker active (request blocking changes fetch/render timing β this is the trigger)
- The console shows
Uncaught TypeError: Cannot read properties of undefined (reading 'clearReset')and React unmounts the entire tree (passive-effect error β error boundaries cannot catch it)
Expected behavior#
an app using react-query without <QueryErrorResetBoundary> should never have its whole tree torn down by an internal context read; a guarded access would degrade gracefully.
How often does this bug happen?#
Every time
Screenshots or Videos#
No response
Platform#
OS:window Browser:Chrome Version:Version 158.0.8127.91 (Official Build) (64-bit)
Tanstack Query adapter#
react-query
TanStack Query version#
v5.108.2
TypeScript version#
No response
Additional context#
No response
tanstack-source added labelsbug
Sign in to join this conversation.