Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(core) - fix issue with ssr-exchange looping for reexecuted ops #1944

Merged
merged 1 commit into from
Sep 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working on this made me think whether or not we should guard for this on line 129 by doing filter(operation => !!data[operation.key] && operation.context.requestPolicy !== "network-only"),

result.stale = true;
revalidated.add(op.key);
reexecuteOperation(client, op);
}

Expand Down