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.63k stars 451 forks source link

Request Policy set to cache-only throws error during build of next.js app with document cache #3457

Closed Thoud closed 9 months ago

Thoud commented 9 months ago

Describe the bug

First of all thanks a lot for your work on this project!

The docs for request policies on document cache mention that cache-only should return the cached data or null.

When using useQuery in a next.js app and setting the request policy to cache-only everything looks as expected in dev mode. However when trying to create a production build with npm run build I get this error: TypeError: Cannot read properties of undefined (reading 'operation').

The expected behaviour would be no build errors and the same result as in dev mode.

Maybe for context why this is an issue for my use case: I tried to leverage the ssr prefetching of queries and want to only display data that has been prefetched server side. This worked fine with the graphCache, but I recently had to move back to document caching. So I'm not sure with which version this bug got introduced.

Reproduction

https://github.com/Thoud/urql-cache-only-issue-demo

Urql version

4.0.6

Validations