Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(react) - Fix Suspense-on-update giving stale results in Concurrent Mode #1308

Merged
merged 8 commits into from
Jan 15, 2021

Conversation

kitten
Copy link
Member

@kitten kitten commented Jan 14, 2021

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 in useQuery for another solution that's more in-line with per-client shortterm caches, e.g. https://github.com/FormidableLabs/urql/tree/refactor/shared-sources

Set of changes

  • Don't close toSuspenseSource sources prematurely when throwing suspense promise
  • Fix cached values in toSuspenseSource from being sent without a prior Pull event
  • Remove delay on resolving the suspense promise
  • Prevent leaks in useSource when the initial state getter throws a suspense promise

@changeset-bot
Copy link

changeset-bot bot commented Jan 14, 2021

🦋 Changeset detected

Latest commit: 06d9080

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
urql Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

After Suspense is triggered on an update all state is preserved
and effects stay active (which we're already relying on to preserve
the scanned state of the query hook).
So we can also keep the suspense source active.
@kitten kitten changed the title (react) - Delay suspenseful updates by an effect-cycle (react) - Fix Suspense-on-update giving stale results in Concurrent Mode Jan 14, 2021
@kitten kitten marked this pull request as ready for review January 14, 2021 18:12
@JoviDeCroock JoviDeCroock merged commit f988961 into main Jan 15, 2021
@JoviDeCroock JoviDeCroock deleted the fix/react-suspense-effects branch January 15, 2021 12:31
@github-actions github-actions bot mentioned this pull request Jan 15, 2021
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.

(graphcache) - Stale result with suspense in development mode
2 participants