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/next) Only restore uncached operation data into ssr-cache #1775

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion exchanges/graphcache/default-storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"./package.json": "./package.json"
},
"dependencies": {
"@urql/core": ">=2.0.0",
"@urql/core": ">=2.1.4",
"wonka": "^4.0.14"
}
}
11 changes: 10 additions & 1 deletion packages/core/src/exchanges/ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,16 @@ export const ssrExchange = (params?: SSRExchangeParams): SSRExchange => {
return merge([forwardedOps$, cachedOps$]);
};

ssr.restoreData = (restore: SSRData) => Object.assign(data, restore);
ssr.restoreData = (restore: SSRData) => {
// Only restore data for uncached operations
const uncached = {};
Object.entries(restore).forEach(([key, value]) => {
if (false === key in data) {
uncached[key] = value;
}
});
return Object.assign(data, uncached);
};
Comment on lines +162 to +171
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, this kinda feels weird to me. Generally the same key in the cache should have the same result across different pages, I'm curious how and why this would deviate.

This would be a breaking change if we were to go for this.

Copy link
Author

Choose a reason for hiding this comment

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

ssr.extractData = () => Object.assign({}, data);

if (params && params.initialState) {
Expand Down