Repository navigation
Description
Summary
In @decocms/tanstack 7.80.0, a request that the site's buildSegment marks as loggedIn turns off the response cache and also every data cache: memory and shared storage, for loaders, fetch and section caches. So every SSR and every ?renderJson for a logged-in shopper reruns all Intelligent Search, catalog and CMS calls from scratch.
Fresh (deco runtime) caches public loaders the same way whether or not the shopper is logged in. Whether a loader is cached is decided by its own cacheKey, and the segment token is part of the key.
Where
packages/tanstack/src/sdk/workerEntry.ts (published src/sdk/workerEntry.ts:2333-2372 in 7.80.0):
const privateRequest =
requestCarriesDraft(request, url) ||
segment?.loggedIn === true || // <- logged-in shopper
request.headers.has("authorization") || ...;
storage = privateRequest || isDevMode() ? null : options.cacheStorage?.(env, request);
...
variant = [..., privateRequest ? crypto.randomUUID() : null]; // unique scope
bindCacheStorage({ storage, disabled: privateRequest || isDevMode(), ... });With disabled: true, createCacheStore get/read/set return early. That covers createCachedLoader, createFetchCache and the section/layout caches, not only the HTML cache.
Fresh reference
The deco runtime (blocks/loader.ts at oficina-dev/deco-runtime@c30a0f6, lines 229-238) bypasses a loader's cache only for no-store/no-cache or when cacheKey returns null. Being logged in does not enter that decision.
For example, VTEX intelligentSearch/productListingPage.ts (deco-apps@60695e7, cacheKey at line 458) keys by getSegmentFromBag(ctx).token. A logged-in shopper whose segment equals the anonymous one shares those entries; a member whose priceTables differ gets their own.
Impact (oficina-tanstack)
- PLP SSR while logged in: 6.3–9.1 s, against ~0.1–1.9 s for the same build when anonymous (cache MISS) and 0.6–1.7 s on the Fresh production site, logged in or not.
- The PLP's in-place pill navigation fetches
?renderJsonwith a 5 s timeout, the same as Fresh. Above that it falls back to a full page load. For logged-in shoppers that fallback is the common case.
Proposal
Split "don't cache the response" from "don't use the data caches":
- Keep the HTML/response cache bypass for every private request, as today.
- For
segment.loggedIn(and only that case: not drafts, previews,authorizationor matcher overrides), keep the data caches on, with the scope built from the segment hash. The hash already distinguishespriceTables, campaigns, sales channel and region, so a member never reads an anonymous price. - Loaders that read the session (user, orders, wishlist, orderForm) must stay outside
createCachedLoader. That is the existing contract, the same one Fresh'scacheKey → nullexpresses. This could be opt-in at first, e.g.dataCacheForLoggedIn: trueincreateDecoWorkerEntryoptions.
Found while investigating QA-049 / QA-165 on deco-sites/oficina-tanstack (#491, #501).
Activity