-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Query call twice with fetchPolicy: no-cache #10540
Comments
Hey @clementloridan 👋 ! Are you by chance using React 18 and React's
|
Hi @jerelmiller, I have the same issue on the react-apollo-error-template. And this template is based already on React 18. (And thk @jerelmiller for your quick answer) |
@clementloridan I'm so sorry, I totally missed your reproduction link when I posted that earlier comment. I could have answered my own question 🤣 . We will take a look at this when we get a chance! |
More info
Issue appear from |
This gets stranger and stranger - with this change, the double-fetch doesn't occur as well: +setTimeout(() => {
const container = document.getElementById("root");
const root = createRoot(container);
root.render(
<ApolloProvider client={client}>
<App />
</ApolloProvider>
);
+}, 500); => if the Apollo client is created at the same time as the first render runs, we see a double-fetch. Otherwise not. PS: because And that now plays a role because of 4a0e8dd - which happened between those two betas that you told us about. |
Which results to a fix for this in userland (for now, this still gives us plenty of stuff to evaluate & talk about internally): const client = new ApolloClient({
cache: new InMemoryCache(),
uri: "https://swapi-graphql.netlify.app/.netlify/functions/index",
ssrMode: typeof window === "undefined",
- ssrForceFetchDelay: 100,
+ ssrForceFetchDelay: typeof window === "undefined" ? 100 : 0,
defaultOptions: {
watchQuery: {
fetchPolicy: "cache-and-network",
nextFetchPolicy: "cache-first",
errorPolicy: "all",
},
query: {
fetchPolicy: "cache-and-network",
nextFetchPolicy: "cache-first",
errorPolicy: "all",
},
mutate: {
errorPolicy: "all",
},
},
}); In a non-SSR-scenario, both |
Issue Writeup #10540Description: Questions
Follow-up questions (may go off into other tangents)
Potential fixDelaying the "unsubscribe" for a tick gives the "next subscription" an option to latch onto an existing non-cache in-memory value. That resolves this specific scenario, but I am not sure if there are other scenarios, where we might need another fix. - return () => subscription.unsubscribe();
+ return () => setTimeout(() => subscription.unsubscribe()); Coincidentally, this fixes also a bug with polling and @jerelmiller @alessbell @benjamn I would need some feedback on this. Is my analysis here okay - is that fix enough, or do we need more? What about the follow-up-question? |
Hi all, the fix for this was merged and should be released with the next patch, probably sometime this week 🚀 |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Issue Description
On a simple page, my
useQuery
oruseLazyQuery
will be fetch twice with fetchPolicy: 'no-cache'.Maybe because of
ssrForceFetchDelay
.Should I miss something about fetchPolicy: no-cache and ssrForceFetchDelay?
Why no-cache? Because I don't manage a lot of data with apollo/client, performance issue.
Thk to helping me :)
Link to Reproduction
https://github.com/clementloridan/react-apollo-error-template
Reproduction Steps
My apollo config:
The text was updated successfully, but these errors were encountered: