(react) - Fix Suspense-on-update giving stale results in Concurrent Mode #1308
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.
Resolve #1303
Summary
Fix edge cases related to Suspense triggering on an update in Concurrent Mode. Previously it was possible for stale state to be preserved across the Suspense update instead of the new state showing up. This has been fixed by preventing the suspending query source from closing prematurely.
See CodeSandbox for reproduction / fix in action: https://codesandbox.io/s/optimistic-andras-f2j1q?file=/src/useQuery.ts
For some next steps it'd be interesting to explore ways to remove the
toSuspenseSource
cache inuseQuery
for another solution that's more in-line with per-client shortterm caches, e.g. https://github.com/FormidableLabs/urql/tree/refactor/shared-sourcesSet of changes
toSuspenseSource
sources prematurely when throwing suspense promisetoSuspenseSource
from being sent without a priorPull
eventuseSource
when the initial state getter throws a suspense promise