Skip to content

Commit

Permalink
(next) - allow subsequent statically generated pages to hydrate the s…
Browse files Browse the repository at this point in the history
…sr-cache (#1602)

* allow subsequent statically generated pages to hydrate the ssr-cache

* remove testing code
  • Loading branch information
JoviDeCroock authored May 3, 2021
1 parent f02178f commit b501be8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/witty-spiders-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'next-urql': minor
---

Allow subsequent static-pages to hydrate the cache
1 change: 1 addition & 0 deletions examples/with-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"urql": "^2.0.2"
},
"scripts": {
"dev": "next dev",
"start": "next",
"build": "next build"
}
Expand Down
2 changes: 2 additions & 0 deletions packages/next-urql/src/with-urql-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ 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 });
} else if (ssr && typeof window !== 'undefined') {
ssr.restoreData(urqlServerState);
}

const clientConfig = getClientConfig(ssr);
Expand Down

0 comments on commit b501be8

Please sign in to comment.