urql-graphql / urql

The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
https://urql.dev/goto/docs
MIT License
8.54k stars 444 forks source link

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

Closed ookil closed 3 months ago

ookil commented 3 months ago

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

JoviDeCroock commented 3 months ago

This seems to be because this check evaluates to false.

When I add

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

This works correctly

ookil commented 3 months ago

@JoviDeCroock thanks a lot!