urql-graphql / urql

The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.

Home Page:https://urql.dev/goto/docs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Invalidating cache in Graphcache doesn't trigger query refetch in Next.js app router

ookil opened this issue · comments

Describe the bug

When using Graphcache with Next.js and app router (with client components) there seems to be an issue that after invalidating cache queries are not refetched and stale data is shown.
This was not an issue with pages but stopped working when migrating to app router.
I created a reproduction that shows the issue. Only after refetching the query with { requestPolicy: "network-only" } fresh data is shown.

Reproduction

https://github.com/ookil/urql-graphcache

Urql version

"@urql/core": "^4.3.0",
"@urql/exchange-graphcache": "^6.5.0",
"@urql/next": "^1.1.1",

Validations

  • I can confirm that this is a bug report, and not a feature request, RFC, question, or discussion, for which GitHub Discussions should be used
  • Read the docs.
  • Follow our Code of Conduct

This seems to be because this check evaluates to false.

When I add

const ssr = ssrExchange({
  isClient: typeof window !== 'undefined'
});

This works correctly

@JoviDeCroock thanks a lot!