Repository navigation
How to architect: local resolver re-populates from ssrExchange #3760
Replies: 1 comment
|
I read through
// On the client we delete results from the cache as they're resolved
cachedOps$ = pipe(cachedOps$, tap(invalidate));const invalidate = (result: OperationResult) => {
invalidateQueue.push(result.operation.key);
if (invalidateQueue.length === 1) {
Promise.resolve().then(() => {
let key: number | void;
while ((key = invalidateQueue.shift())) {
data[key] = null;
}
});
}
};The moment a query is served once from the SSR cache on the client, its entry gets set to ssr.restoreData = (restore: SSRData) => {
for (const key in restore) {
// We only restore data that hasn't been previously invalidated
if (data[key] !== null) {
data[key] = restore[key];
}
}
};So once a given operation key has been served and invalidated, any later Given that, trying to make a local resolver "peek into" the SSR cache is fighting the exchange's design rather than working with it, The two practical paths that actually work with how
If you specifically need "cached instantly, but always double-check network in the background", |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
We are running Next Pages Router app, having
getServerSideProps.The first time user visits a product page, the
ssrExchangepopulates correctly the client's cache withProductQuery.The consequtive visits of the same product, the
getServerSidePropsis designed by us to send a freshProductQueryin thessrExchange.But it's not needed/used, the cached version is already present...
Which was ok until we we wanted to have fresh data from the
ProductQueryon each visit.I tried to use local resolver and return
undefined(for the ProductQuery).Thinking that the
ssrExchangewill provide the already presentProductQuery.But somehow it's not working.
When I debug naively the source code...
It seems after returning
undefinedfrom a resolver, it does trigger thessrExchangedata correctly.But then it tries to
updateCacheWithResultand inside it does_query(queryResult) the sameProductQueryand the resolver is triggered again and returnsundefinedand it loops in this pattern.Any ideas, advice, please?
I cannot play with (work with) ssrExchange cache from resolvers, right?
All reactions