Closed luchillo17 closed 11 months ago
The specific file where I got the symbols from: package/src/ssr/ApolloRehydrateSymbols.tsx
Hi @luchillo17, good point, this needs some way to reset in tests.
I don't want to expose the symbols though - this is an implementation detail and can change in future versions. Instead, I've added a resetNextSSRApolloSingletons
function in #35.
You can use it like
afterEach(resetNextSSRApolloSingletons);
As for your question
Why does this need to store the state in the window?
These singletons are needed to transport data from SSR into the browser - as the Client in the browser already starts up before the SSR pass finishes, we need to continuously push data from the server into the browser client.
Next.js actually does something very similar to this, take a look at window.__next_f
.
A 0.2.0
release with this will be available in a moment :)
Awesome, will try it ASAP.
Not working unfortunately, these are your resets:
delete window[ApolloRehydrationCache];
delete window[ApolloResultCache];
delete window[ApolloSSRDataTransport];
And these are mine:
delete window[ApolloResultCache];
delete window[ApolloClientSingleton];
delete window[SuspenseCacheSingleton];
@phryneas can we re-open this? the resets you put were not enough for my test...
Hi @luchillo17 I'm sorry for the delay - I'll put out a fix for this in a bit. (And yes, please always just reopen or open a new issue - it helps the visibility a lot!)
Released with https://github.com/apollographql/apollo-client-nextjs/releases/tag/v0.2.2 - if there's anything else, please reopen, or create a new issue :)
Working perfectly, thanks.
Problem
I am probably doing something weird to have a wrapper defined in an NX monorepo & have it tested like this, but so far this is the most concise test I could make.
The issue stems from trying to check if the ApolloClient in the context has the correct link URL, since this lib at the moment seems to store state in the
global.window
, the only way for me to make more than 1 test work is by resetting the content of the variables this library sets inwindow
.2 things I want to ask:
window
?window
interface is bound to be error prone.