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

Suspense: 'network-only' fetches twice #1243

Closed
StevenLangbroek opened this issue Dec 18, 2020 · 3 comments · Fixed by #1335
Closed

Suspense: 'network-only' fetches twice #1243

StevenLangbroek opened this issue Dec 18, 2020 · 3 comments · Fixed by #1335
Labels
bug 🐛 Oh no! A bug or unintented behaviour.

Comments

@StevenLangbroek
Copy link
Contributor

StevenLangbroek commented Dec 18, 2020

Hey folks!

Opening an issue after a long chat with @kitten. When suspense is enabled, and you set a hook or component to network-only, the request fires twice.

Phil said this is expected behavior given the current implementation (which makes sense, the component is rendered twice, once before suspending and then again after the initial request resolves). That being said; I think this will still surprise folks when they migrate to suspense in the future, and should be considered a bug I think.

urql version & exchanges:

  • latest urql
  • graphcache

Steps to reproduce

https://codesandbox.io/s/gifted-bohr-honuf?file=/src/App.tsx

Expected behavior

The request only fires once

Actual behavior

The request fires twice

Is there anything else I can provide or explain? Here to help 🙏

@StevenLangbroek StevenLangbroek added the bug 🐛 Oh no! A bug or unintented behaviour. label Dec 18, 2020
@kitten
Copy link
Member

kitten commented Dec 18, 2020

Just leaving a note here for debugging, as discussed, with network-only this is likely expected behaviour and not avoidable, but this behaviour also happens with cache-and-network

@StevenLangbroek
Copy link
Contributor Author

@kitten so I think I mentioned this, but if useState values can be persisted during suspense, can't we hang on to a reference somehow to know we shouldn't make this request again?

See https://codesandbox.io/s/pedantic-volhard-8fvbu

@kitten
Copy link
Member

kitten commented Dec 18, 2020

My concern is more with cache-and-network and effects. We can't hang on to the effect and our state is computed. So it's unfortunately not a matter of hanging on to state because we can't accurately determine and predict what lifecycle we're currently following (which is intended on React's part) and we also won't know when and how data has or will change from a Client perspective.

In other words, detecting Suspense and predicting what to do after won't do us any good when we can't tell what component we're returning to. Concurrent makes this situation even harder since we can't tell if and when a component is active again; for all intents and purposes it'll be a "new instance". Lastly having state around still or not won't either do us any good if we need the query stream to become active (while it can't stay active during an interrupt) when the component "resumes"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Oh no! A bug or unintented behaviour.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants