Repository navigation
fix: cache deferred section data across SPA navigations + registerSectionsSync module form - #8
Conversation
DeferredSectionWrapper previously stored resolved section data in
component-local useState. Each SPA navigation away and back caused the
component to unmount/remount with section=null, triggering a new
_serverFn fetch — producing an empty → skeleton → content transition
that caused significant CLS (especially for product shelves).
Add a module-level Map<stableKey, {section, ts}> cache with a TTL
matching cmsRouteConfig staleTime (5 min prod / 5 s dev):
- useState initializer reads from cache on client mount
- stableKey change detection restores from cache instead of always
setting section=null
- loadFn callbacks store the resolved section in the cache
Result: navigating PDP → home reuses cached section data and renders
product shelves immediately — no empty/skeleton phase on back navigation.
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…e sectionOptions
Previously registerSectionsSync only accepted ComponentType<any> references.
DeferredSectionWrapper would start with optionsReady=false even for sync-registered
sections and call preloadSectionModule() async to discover LoadingFallback —
causing a brief null render before the skeleton appeared.
Extend the API to accept either a plain component or a full module object:
registerSectionsSync({
"site/sections/Product/ProductShelf.tsx": ProductShelfModule,
});
// where ProductShelfModule = { default, LoadingFallback?, ErrorFallback? }
When the module form is used, LoadingFallback and ErrorFallback are stored
in sectionOptions immediately at registration time. DeferredSectionWrapper
then initializes optionsReady=true and renders the correct skeleton on the
first paint — no async round-trip needed.
Backwards compatible: plain ComponentType<any> still works unchanged.
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
There was a problem hiding this comment.
1 issue found across 2 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/hooks/DecoPageRenderer.tsx">
<violation number="1" location="src/hooks/DecoPageRenderer.tsx:221">
P1: Reusing cached sections here is unsafe because the cache key ignores `deferred.rawProps`, so prop changes for the same slot can render stale data and never refetch.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Migrate all missing matchers from Fresh/Deno to TanStack Start: - location.ts: geo-targeting via __cf_geo_* cookies with country name-to-ISO mapping - userAgent.ts: substring and regex matching on User-Agent - environment.ts: production vs development via process.env.NODE_ENV - multi.ts: AND/OR combinator with recursive evaluateMatcher - negate.ts: boolean NOT with recursive evaluateMatcher Also: - Export evaluateMatcher from cms/resolve for recursive matcher evaluation - Export injectGeoCookies from sdk/workerEntry for CF geo data injection - Register admin schemas for all 5 new matchers Co-Authored-By: Claude Opus 4.6 <[email protected]>
The cache key for deferred sections only used pagePath, component, and index — ignoring rawProps. If CMS props changed for the same slot, stale cached data would be served. Add a DJB2 hash of rawProps to the key. Co-Authored-By: Claude Opus 4.6 <[email protected]>
There was a problem hiding this comment.
3 issues found across 5 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/sdk/workerEntry.ts">
<violation number="1" location="src/sdk/workerEntry.ts:314">
P1: Adding Cloudflare geo data to `Cookie` makes location-based matchers affect the rendered HTML, but the worker cache key does not vary by those cookies. The first location to fill the edge cache can therefore leak geo-targeted content to other locations.</violation>
</file>
<file name="src/matchers/builtins.ts">
<violation number="1" location="src/matchers/builtins.ts:252">
P2: `regionCode` rules are reading the wrong cookie, so location matches by region code will never work against Cloudflare geo data.</violation>
<violation number="2" location="src/matchers/builtins.ts:280">
P1: Guard the `match` regex before compiling it; this currently allows request-time ReDoS patterns from CMS matcher data.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
- workerEntry: include CF country in cache key to prevent geo-targeted content leaking across locations - builtins: guard userAgent regex with isSafePattern to prevent ReDoS - builtins: read __cf_geo_region_code (short code) with fallback to __cf_geo_region (full name) for location matcher regionCode matching Co-Authored-By: Claude Opus 4.6 <[email protected]>
There was a problem hiding this comment.
3 issues found across 3 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/sdk/workerEntry.ts">
<violation number="1" location="src/sdk/workerEntry.ts:432">
P2: Adding `__cf_country` to cache keys breaks cache purge for geo-targeted pages, because purge never deletes the country-specific variants.</violation>
<violation number="2" location="src/sdk/workerEntry.ts:432">
P1: `__cf_country` is skipped whenever `buildSegment` is enabled, so geo-targeted pages can still leak across countries for segmented caches.</violation>
</file>
<file name="src/matchers/builtins.ts">
<violation number="1" location="src/matchers/builtins.ts:254">
P2: Preferring `__cf_geo_region_code` here breaks existing location rules that were authored against the previous region-name value. Keep matching the legacy region name as well so old geo-targeted content does not stop rendering after deploy.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
…gion compat - Move CF country cache key injection before buildSegment early return so geo-targeted content is never leaked regardless of cache key strategy - Accept optional countries[] in purge body to clear geo-specific variants - Match regionCode rules against both short code and full name so existing rules authored against either format continue working after deploy Co-Authored-By: Claude Opus 4.6 <[email protected]>
There was a problem hiding this comment.
2 issues found across 2 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/sdk/workerEntry.ts">
<violation number="1" location="src/sdk/workerEntry.ts:420">
P1: Vary geo-targeted cache keys by region/city too, not just country.</violation>
<violation number="2" location="src/sdk/workerEntry.ts:490">
P1: Purge requests without `countries` no longer invalidate the live cache entries.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
- Cache key now includes full geo tuple (country|region|city) via __cf_geo param so location matcher results at any granularity do not leak - Purge accepts geo strings matching the __cf_geo format and always purges the non-geo variant as baseline Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
🎉 This PR is included in version 0.21.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
…anStack Start, esbuild) (#832) Closes the open Dependabot alerts in one PR, with the lockfile. The Dependabot PRs (#811, #828, #747) only touch `package.json`, so they all fail `bun install --frozen-lockfile` in CI. | Package | From | To | Alerts | |---|---|---|---| | `react-server-dom-webpack` (tanstack-rsc-smoke) | 19.2.7 | 19.2.9 | #19, critical: RSC RCE, GHSA-xqc2-xf4c-x3h3 | | `react` / `react-dom` (all pinned workspaces) | 19.2.7 | 19.2.9 | peer floor of the above | | `next` (nextjs, compat-v7, nextjs-binding-smoke) | 16.3.8 | 16.4.6 | #10–12, #14, #15, #17, #18, #20–22 | | `@tanstack/react-start` (tanstack, compat-v7, smokes) | 1.168.58 | 1.168.61 | #2–4, #7, #9 | | `@tanstack/react-router` | 1.170.39 | 1.170.42 | the version react-start 1.168.61 pins, so it stays a single copy | | `esbuild` (blocks, tanstack, compat-v7) | ^0.27.3 | ^0.28.2 | #5, #6, #8 (low) | `bun.lock` was regenerated with bun 1.3.5 (the `packageManager`). React dedupes to a single 19.2.9 at the root, with no nested copies. Vite still has its own transitive `[email protected]` (its own range); that is outside our manifests. Supersedes #811, #828 and #747. ### Verified locally (bun 1.3.5, node 24) - `bun install --frozen-lockfile` ✅ - `bun run typecheck` ✅ · `bun run lint` ✅ - `bun x vitest run`: 3388 passed, 0 failed ✅ (includes `tests/release.test.ts`) - `examples/tanstack-worker-smoke`: build + smoke ✅ - `examples/nextjs-binding-smoke`: build + smoke ✅ - `examples/tanstack-rsc-smoke`: build + typecheck ✅ 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Bumps several dependencies to clear open Dependabot security alerts, including a critical RCE in `react-server-dom-webpack` (GHSA-xqc2-xf4c-x3h3). The lockfile was regenerated so `bun install --frozen-lockfile` passes — React dedupes to a single 19.2.9 copy. **Dependencies** - `react`, `react-dom`, and `react-server-dom-webpack` 19.2.7 → 19.2.9 - `next` 16.3.8 → 16.4.6 - `@tanstack/react-start` 1.168.58 → 1.168.61, with `@tanstack/react-router` 1.170.42 - `esbuild` ^0.27.3 → ^0.28.2; Vite's own transitive `[email protected]` is untouched - Typecheck, lint, the full test suite (3388 passed), and the Next.js and TanStack smoke builds all pass <sup>Written for commit 123acc8. Summary will update on new commits.</sup> <a href="https://cubic.dev/pr/decocms/blocks/pull/832?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a> <a href="https://www.cubic.dev/action/auto-fix/pr/decocms/blocks/832?returnTo=https%3A%2F%2Fgithub.com%2Fdecocms%2Fblocks%2Fpull%2F832&source=description" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img alt="Turn on auto-fix" src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a> <!-- End of auto-generated description by cubic. --> Co-authored-by: Claude Opus 5.5 <[email protected]>
Problem
Two related issues in
DeferredSectionWrapperthat caused CLS on SPA navigation back to a previously-visited page (e.g. PDP → home):1. No cross-navigation cache for deferred section data
DeferredSectionWrapperstored resolved section data in component-localuseState. Each navigation away unmounts the component; navigating back remounts it withsection=null, triggering a new_serverFnfetch. During this fetch (~200–800ms even with server-side caching), the section goes through:This causes a significant CLS spike, especially for product shelves.
2.
optionsReady=falsefor sync-registered sectionsDeferredSectionWrapperinitializesoptionsReady = !!getSectionOptions(component). For sections registered viaregisterSectionsSync,sectionOptionswas never populated at registration time — only afterpreloadSectionModule()resolved async. This caused a briefnullrender before the skeleton appeared, even for sections whose module was already loaded.Solution
Fix 1 — Module-level deferred section cache
Added a
Map<stableKey, {section, ts}>at module level inDecoPageRenderer.tsx:cmsRouteConfigstaleTime: 5 min prod / 5 s devuseStateinitializer reads from cache on client mountstableKeychange detection restores from cache instead of always resetting tonullloadFncallbacks store the resolved section in the cacheResult: navigating PDP → home renders deferred sections immediately from cache — no empty/skeleton phase.
Fix 2 —
registerSectionsSyncaccepts full module objectsExtended the API (backwards compatible) to accept either a
ComponentTypeor a full module object:When the module form is used,
LoadingFallbackandErrorFallbackare stored insectionOptionsimmediately.DeferredSectionWrapperinitializesoptionsReady=trueand shows the correct skeleton on first paint.Test plan
registerSectionsSyncwith plain component still works (backwards compat)registerSectionsSyncwith module object populatesgetSectionOptions()immediately🤖 Generated with Claude Code
Summary by cubic
Fixes CLS on SPA back navigation by caching deferred section data with prop-aware keys, and updates
registerSectionsSyncto accept full module objects so skeletons render on first paint. Adds geo-safe caching usingcountry|region|citykeys with purge support, plus new matchers and safety guards.Bug Fixes
country|region|city; purge acceptscountries[]as geo strings and always clears the non-geo variant to prevent content leaks.__cf_geo_region_code(fallback to region name) and matches both short code and full name.New Features
registerSectionsSyncaccepts full module objects ({ default, LoadingFallback?, ErrorFallback? }) to show the correct skeleton on first paint (backwards compatible).evaluateMatcherandinjectGeoCookies; registered admin schemas.Written for commit 9e67d7c. Summary will update on new commits.