-
Hey, I'm trying to figure out the best way to handle a situation where the query returns different results during static site generation compared to the client-side query. This happens because during static site generation I only wish to pre-build the public data. However, any non-public data will briefly flash a 404 page, as seen in my reproduction with a pokedex example api, where the API hides pokemon with fizzbuzz ids from the server but not the client. If you take a look at Try visiting There is always a render where Is there anyway to detect the situation where the server returned the fallback page, but urql has yet to perform the query? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The solution we found was to not populate cache data unless we find data: export async function getStaticProps({ params }) {
const ssrCache = ssrExchange({ isClient: false });
const client = initUrqlClient(getConfig(ssrCache), false);
// This query is used to populate the cache for the query
// used on this page.
const { data } = await client
.query(POKEMON_QUERY, { id: params.id })
.toPromise();
// Do not extract and pass urql state unless we found data
if (!data?.pokemon) return { props: {} };
return {
props: {
// urqlState is a keyword here so withUrqlClient can pick it up.
urqlState: ssrCache.extractData(),
},
};
} That is, skip passing That way, the client can retry the query (using auth cookies/headers) and decide whether to display a 404 or not. |
Beta Was this translation helpful? Give feedback.
The solution we found was to not populate cache data unless we find data:
That is, skip passing
s…