fix(react): resolve infinite Suspense retry loop on promise rejection#2323
Open
schettn wants to merge 1 commit intogqty-dev:mainfrom
Open
fix(react): resolve infinite Suspense retry loop on promise rejection#2323schettn wants to merge 1 commit intogqty-dev:mainfrom
schettn wants to merge 1 commit intogqty-dev:mainfrom
Conversation
Introduce a stable resource cache for Suspense to ensure consistent
thrown promises across renders. This specifically addresses issues
when using `suspense: true` with the `prepare` helper.
The stable cache ensures the fix works in both CSR and SSR environments.
While a simple `setState({ error })` might suffice for CSR, it fails on
the server because state is lost during the retry phase. By caching the
resource, we guarantee that rejected promises are correctly thrown as
errors, allowing them to be caught by an ErrorBoundary instead of
triggering an infinite retry loop.
- Add `suspense-resource.ts` for managing stable Suspense resources.
- Update `useQuery` to utilize `suspenseResourceCache` for `prepare` calls.
- Add detailed comments on hashing, SSR state persistence, and error handling.
schettn
commented
Apr 24, 2026
| // We create a unique hash for the current query based on the selections | ||
| // and operation parameters. This ensures that we can identify if we're | ||
| // fetching the same data across renders. | ||
| const queryHash = Array.from(selections) |
Author
There was a problem hiding this comment.
@vicary maybe there is a better way to build the cache key
Member
|
@schettn Thanks for the PR. There has been a boundary tension between imperative and reactive (i.e. with and without Please do let me know if your fork is working for your use case, that information helps. |
Author
|
Decided to go with a packed build instead. Thanks anyway! |
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.
Introduce a stable resource cache for Suspense to ensure consistent
thrown promises across renders. This specifically addresses issues
when using
suspense: truewith thepreparehelper.The stable cache ensures the fix works in both CSR and SSR environments.
While a simple
setState({ error })might suffice for CSR, it fails onthe server because state is lost during the retry phase. By caching the
resource, we guarantee that rejected promises are correctly thrown as
errors, allowing them to be caught by an ErrorBoundary instead of
triggering an infinite retry loop.
suspense-resource.tsfor managing stable Suspense resources.useQueryto utilizesuspenseResourceCacheforpreparecalls.