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

fetchPolicy and nextFetchPolicy have fixed values for PreloadQuery #429

Open
addemod opened this issue Feb 13, 2025 · 1 comment
Open

fetchPolicy and nextFetchPolicy have fixed values for PreloadQuery #429

addemod opened this issue Feb 13, 2025 · 1 comment

Comments

@addemod
Copy link

addemod commented Feb 13, 2025

When using the PreloadQuery, you will get a TypeScript error if you're trying to set the value of fetchPolicy to something other than cache-first.
nextFetchPolicy is typed to always be undefined.

type RestrictedPreloadOptions = {
    fetchPolicy?: "cache-first";
    returnPartialData?: false;
    nextFetchPolicy?: undefined;
    pollInterval?: undefined;
};
type PreloadQueryOptions<TVariables, TData> = QueryOptions<TVariables, TData> & RestrictedPreloadOptions;

Is this intended?

@phryneas
Copy link
Member

phryneas commented Feb 13, 2025

Yes, that's intended, although we might change that one allowed default soon due to implementation changes. Generally, you shouldn't touch it for PreloadQuery, whichever default we choose it probably the only one that will work as expected.

PreloadQuery works by querying data in your RSC implementation and transporting that over into SSR and the Browser clients. There, that data needs to be picked up by the useReadQuery hook without starting an additional network request.

That's why in this current implemtentation we opt for cache-first, which will on the server force a network request (so we have something we can transport) and in the client will force a cache read so you get the transported data.

That will change in the next release as we reworked PreloadQuery and the internal data transport, but again, there we will be limiting you to the fetchPolicy that works best.

If you want to cache things on the RSC level, please see your framework's network layer caching - PreloadQuery will always operate on an empty cache to ensure that no data from other queries bleeds into the query that should be transported.

Similar things for nextFetchPolicy, which would cause unintended additional network requests in this data transport scenario or (if you specify the callback function notation) would even be non-serializable and couldn't be transported.

Generally: even if you ignored the TypeScript errors - we will override whatever you specify here with values that we allow for on a TS level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants