Skip to content

Commit

Permalink
Add staleWhileRevalidate to next-urql
Browse files Browse the repository at this point in the history
  • Loading branch information
kitten committed Aug 11, 2021
1 parent cce3820 commit 64a0ab4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/new-horses-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'next-urql': minor
---

Add new `staleWhileRevalidate` option from the `ssrExchange` addition to `withUrqlClient`'s options. This is useful when Next.js is used in static site generation (SSG) mode.
1 change: 1 addition & 0 deletions packages/next-urql/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ export interface SSRExchange extends Exchange {
export interface WithUrqlClientOptions {
ssr?: boolean;
neverSuspend?: boolean;
staleWhileRevalidate?: boolean;
}
6 changes: 5 additions & 1 deletion packages/next-urql/src/with-urql-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ export function withUrqlClient(

if (!ssr || typeof window === 'undefined') {
// We want to force the cache to hydrate, we do this by setting the isClient flag to true
ssr = ssrExchange({ initialState: urqlServerState, isClient: true });
ssr = ssrExchange({
initialState: urqlServerState,
isClient: true,
staleWhileRevalidate: options!.staleWhileRevalidate
});
} else if (!version) {
ssr.restoreData(urqlServerState);
}
Expand Down

0 comments on commit 64a0ab4

Please sign in to comment.