From 64a0ab440c29e650647a193acda361f2f50f9305 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Wed, 11 Aug 2021 13:21:09 +0100 Subject: [PATCH] Add staleWhileRevalidate to next-urql --- .changeset/new-horses-bow.md | 5 +++++ packages/next-urql/src/types.ts | 1 + packages/next-urql/src/with-urql-client.ts | 6 +++++- 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 .changeset/new-horses-bow.md diff --git a/.changeset/new-horses-bow.md b/.changeset/new-horses-bow.md new file mode 100644 index 0000000000..e7761d0b2c --- /dev/null +++ b/.changeset/new-horses-bow.md @@ -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. diff --git a/packages/next-urql/src/types.ts b/packages/next-urql/src/types.ts index 7547851605..5a3795cb0a 100644 --- a/packages/next-urql/src/types.ts +++ b/packages/next-urql/src/types.ts @@ -54,4 +54,5 @@ export interface SSRExchange extends Exchange { export interface WithUrqlClientOptions { ssr?: boolean; neverSuspend?: boolean; + staleWhileRevalidate?: boolean; } diff --git a/packages/next-urql/src/with-urql-client.ts b/packages/next-urql/src/with-urql-client.ts index 9adead8ce1..797d142020 100644 --- a/packages/next-urql/src/with-urql-client.ts +++ b/packages/next-urql/src/with-urql-client.ts @@ -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); }