Skip to content

Commit

Permalink
fix issue with ssr-exchange looping for reexecuted ops (#1944)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock authored Sep 11, 2021
1 parent b90b6d5 commit 63eec7e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/flat-queens-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@urql/core': patch
---

Fix issue where the ssr-exchange would loop due to checking network-only revalidations
5 changes: 4 additions & 1 deletion packages/core/src/exchanges/ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ const deserializeResult = (
hasNext: result.hasNext,
});

const revalidated = new Set<number>();

/** The ssrExchange can be created to capture data during SSR and also to rehydrate it on the client */
export const ssrExchange = (params?: SSRExchangeParams): SSRExchange => {
const staleWhileRevalidate = !!(params && params.staleWhileRevalidate);
Expand Down Expand Up @@ -128,8 +130,9 @@ export const ssrExchange = (params?: SSRExchangeParams): SSRExchange => {
map(op => {
const serialized = data[op.key]!;
const result = deserializeResult(op, serialized);
if (staleWhileRevalidate) {
if (staleWhileRevalidate && !revalidated.has(op.key)) {
result.stale = true;
revalidated.add(op.key);
reexecuteOperation(client, op);
}

Expand Down

0 comments on commit 63eec7e

Please sign in to comment.