@decocms/blocks 8.0.0 → 8.1.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/bin/deco.js +13 -0
  2. package/package.json +39 -3
  3. package/src/cms/applySectionConventions.ts +26 -2
  4. package/src/cms/blockSource.ts +37 -0
  5. package/src/cms/client.ts +5 -0
  6. package/src/cms/deferredTrigger.ts +58 -0
  7. package/src/cms/draftSource.ts +171 -57
  8. package/src/cms/index.ts +32 -3
  9. package/src/cms/loader.ts +318 -59
  10. package/src/cms/registry.ts +22 -0
  11. package/src/cms/renderJson.ts +179 -0
  12. package/src/cms/resolve.ts +396 -95
  13. package/src/cms/schema.ts +9 -5
  14. package/src/cms/sectionLoaders.ts +106 -56
  15. package/src/hooks/Image.tsx +70 -6
  16. package/src/hooks/LiveControls.tsx +30 -8
  17. package/src/hooks/Stats.tsx +134 -0
  18. package/src/hooks/index.ts +5 -0
  19. package/src/hooks/useLoadMore.ts +100 -0
  20. package/src/index.ts +37 -0
  21. package/src/middleware/observability.ts +173 -16
  22. package/src/preview/DraftPreviewBadge.tsx +306 -0
  23. package/src/preview/decoMark.ts +11 -0
  24. package/src/preview/index.ts +8 -0
  25. package/src/protocol/assets.ts +124 -0
  26. package/src/protocol/canonical.ts +7 -0
  27. package/src/protocol/ciphertext.ts +6 -0
  28. package/src/protocol/client.ts +170 -0
  29. package/src/protocol/conformance/cases/assets.ts +81 -0
  30. package/src/protocol/conformance/cases/guards.ts +314 -0
  31. package/src/protocol/conformance/cases/reads.ts +168 -0
  32. package/src/protocol/conformance/cases/types.ts +9 -0
  33. package/src/protocol/conformance/cases/wire.ts +138 -0
  34. package/src/protocol/conformance/cases/writes.ts +345 -0
  35. package/src/protocol/conformance/contentHashFixtures.ts +79 -0
  36. package/src/protocol/conformance/context.ts +222 -0
  37. package/src/protocol/conformance/index.ts +140 -0
  38. package/src/protocol/errors.ts +142 -0
  39. package/src/protocol/index.ts +39 -0
  40. package/src/protocol/keys.ts +279 -0
  41. package/src/protocol/params.ts +67 -0
  42. package/src/protocol/secrets.ts +231 -0
  43. package/src/protocol/server/assets.ts +119 -0
  44. package/src/protocol/server/auth.ts +49 -0
  45. package/src/protocol/server/bodyCache.ts +84 -0
  46. package/src/protocol/server/content.ts +175 -0
  47. package/src/protocol/server/core.ts +112 -0
  48. package/src/protocol/server/handler.ts +102 -0
  49. package/src/protocol/server/http.ts +139 -0
  50. package/src/protocol/server/index.ts +11 -0
  51. package/src/protocol/server/methods/apply.ts +341 -0
  52. package/src/protocol/server/methods/read.ts +156 -0
  53. package/src/protocol/server/rpc.ts +136 -0
  54. package/src/protocol/storage/fs/hash.ts +21 -0
  55. package/src/protocol/storage/fs/index.ts +338 -0
  56. package/src/protocol/storage/fs/lock.ts +68 -0
  57. package/src/protocol/storage/fs/transaction.ts +183 -0
  58. package/src/protocol/storage/fs/unsupported.ts +15 -0
  59. package/src/protocol/storage/memory.ts +238 -0
  60. package/src/protocol/storage.ts +182 -0
  61. package/src/protocol/types.ts +172 -0
  62. package/src/sdk/abTesting.ts +60 -3
  63. package/src/sdk/analytics.ts +72 -2
  64. package/src/sdk/cacheHeaders.ts +210 -10
  65. package/src/sdk/cacheStorage.ts +287 -0
  66. package/src/sdk/cachedLoader.ts +143 -90
  67. package/src/sdk/crypto.ts +16 -2
  68. package/src/sdk/deepOmit.ts +52 -0
  69. package/src/sdk/encoding.ts +2 -5
  70. package/src/sdk/experiments.ts +314 -0
  71. package/src/sdk/fetchCache.ts +269 -0
  72. package/src/sdk/fetchTimeout.ts +58 -0
  73. package/src/sdk/flags.ts +38 -8
  74. package/src/sdk/index.ts +7 -0
  75. package/src/sdk/instrumentedFetch.ts +25 -2
  76. package/src/sdk/nonce.ts +46 -0
  77. package/src/sdk/normalizeUrls.ts +2 -2
  78. package/src/sdk/observability.ts +8 -1
  79. package/src/sdk/otel.ts +131 -25
  80. package/src/sdk/otelHttpLog.ts +4 -4
  81. package/src/sdk/otelHttpMeter.ts +39 -13
  82. package/src/sdk/otelHttpTracer.ts +4 -4
  83. package/src/sdk/redirects.ts +113 -5
  84. package/src/sdk/responseCache.ts +82 -0
  85. package/src/sdk/urlUtils.ts +49 -0
  86. package/src/sdk/useSuggestions.ts +1 -1
  87. package/src/v8/analytics.ts +50 -0
  88. package/src/v8/background.ts +107 -0
  89. package/src/v8/builtins/data.ts +23 -0
  90. package/src/v8/builtins/index.ts +26 -0
  91. package/src/v8/builtins/lazy.ts +23 -0
  92. package/src/v8/builtins/legacy.ts +65 -0
  93. package/src/v8/builtins/matchers.ts +31 -0
  94. package/src/v8/builtins/multivariate.ts +25 -0
  95. package/src/v8/builtins/secret.ts +82 -0
  96. package/src/v8/canonical.ts +117 -0
  97. package/src/v8/ciphertext.ts +158 -0
  98. package/src/v8/cli/builtins.ts +20 -0
  99. package/src/v8/cli/check/index.ts +774 -0
  100. package/src/v8/cli/check/messages.ts +168 -0
  101. package/src/v8/cli/content.ts +287 -0
  102. package/src/v8/cli/index.ts +17 -0
  103. package/src/v8/cli/log.ts +18 -0
  104. package/src/v8/cli/main.ts +12 -0
  105. package/src/v8/cli/root.ts +66 -0
  106. package/src/v8/cli/run.ts +236 -0
  107. package/src/v8/cli/schema/builtinSchemas.ts +236 -0
  108. package/src/v8/cli/schema/generate.ts +507 -0
  109. package/src/v8/cli/schema/index.ts +63 -0
  110. package/src/v8/cli/schema/tsProgram.ts +497 -0
  111. package/src/v8/cli/schema/typeToSchema.ts +689 -0
  112. package/src/v8/cli/serve/server.ts +303 -0
  113. package/src/v8/cli/watch.ts +86 -0
  114. package/src/v8/client.ts +147 -0
  115. package/src/v8/cms.ts +237 -0
  116. package/src/v8/content.ts +195 -0
  117. package/src/v8/draft.ts +136 -0
  118. package/src/v8/errors.ts +59 -0
  119. package/src/v8/fetch.ts +152 -0
  120. package/src/v8/identity.ts +65 -0
  121. package/src/v8/index.ts +39 -0
  122. package/src/v8/json.ts +74 -0
  123. package/src/v8/matchRoute.ts +204 -0
  124. package/src/v8/remoteLoader.ts +282 -0
  125. package/src/v8/resolver.ts +278 -0
  126. package/src/v8/secrets.ts +17 -0
  127. package/src/v8/telemetry.ts +533 -0
  128. package/src/v8/types.ts +240 -0
  129. package/src/cms/blockSource.test.ts +0 -76
  130. package/src/cms/client.browserBundle.test.ts +0 -44
  131. package/src/cms/draftSource.test.ts +0 -343
  132. package/src/cms/layoutCacheRace.test.ts +0 -181
  133. package/src/cms/loadDecofileDirectory.test.ts +0 -109
  134. package/src/cms/loader.test.ts +0 -200
  135. package/src/cms/registry.test.ts +0 -110
  136. package/src/cms/resolve.test.ts +0 -980
  137. package/src/cms/schema.test.ts +0 -356
  138. package/src/cms/sectionLoaderContext.test.ts +0 -111
  139. package/src/cms/sectionLoaders.test.ts +0 -533
  140. package/src/cms/sectionMixins.test.ts +0 -167
  141. package/src/cms/stickyFlags.test.ts +0 -117
  142. package/src/flags/flags.test.ts +0 -148
  143. package/src/hooks/Image.test.ts +0 -100
  144. package/src/hooks/RenderSection.test.tsx +0 -81
  145. package/src/matchers/builtins.test.ts +0 -318
  146. package/src/matchers/override.test.ts +0 -205
  147. package/src/middleware/hydrationContext.test.ts +0 -61
  148. package/src/middleware/observability.test.ts +0 -242
  149. package/src/middleware/validateSection.test.ts +0 -147
  150. package/src/sdk/abTesting.test.ts +0 -326
  151. package/src/sdk/cacheHeaders.test.ts +0 -115
  152. package/src/sdk/cachedLoader.test.ts +0 -122
  153. package/src/sdk/cachedLoaderModule.test.ts +0 -209
  154. package/src/sdk/cn.test.ts +0 -34
  155. package/src/sdk/composite.test.ts +0 -121
  156. package/src/sdk/cookie.test.ts +0 -108
  157. package/src/sdk/encoding.test.ts +0 -71
  158. package/src/sdk/env.test.ts +0 -33
  159. package/src/sdk/flags.test.ts +0 -91
  160. package/src/sdk/http.test.ts +0 -71
  161. package/src/sdk/inflightTimeout.test.ts +0 -35
  162. package/src/sdk/instrumentedFetch.test.ts +0 -559
  163. package/src/sdk/invoke.test.ts +0 -115
  164. package/src/sdk/logger.test.ts +0 -432
  165. package/src/sdk/otel.test.ts +0 -526
  166. package/src/sdk/otelAdapters.test.ts +0 -89
  167. package/src/sdk/otelHttpLog.test.ts +0 -457
  168. package/src/sdk/otelHttpMeter.test.ts +0 -292
  169. package/src/sdk/otelHttpTracer.test.ts +0 -474
  170. package/src/sdk/requestContextStorage.browser.test.ts +0 -29
  171. package/src/sdk/urlRedaction.test.ts +0 -73
  172. package/src/sdk/useDevice.test.ts +0 -130
  173. package/src/sdk/useScript.test.ts +0 -128
  174. package/src/sdk/useSuggestions.test.ts +0 -230
  175. package/tsconfig.json +0 -7
@@ -1,9 +1,14 @@
1
1
  import { getMatchersOverride, getRuleOverrideId, hasMatchersOverride } from "../matchers/override";
2
2
  import { getMeter, MetricNames, withTracing } from "../middleware/observability";
3
+ import { createCacheStore } from "../sdk/cacheStorage";
4
+ import { detectDevice } from "../sdk/detectDevice";
3
5
  import { djb2Hex } from "../sdk/djb2";
6
+ import { stickyDecide } from "../sdk/experiments";
4
7
  import { parseSegmentCookie, SEGMENT_COOKIE, type StoredFlag, trafficToPct } from "../sdk/flags";
5
8
  import { withInflightTimeout } from "../sdk/inflightTimeout";
6
9
  import { normalizeUrlsInObject } from "../sdk/normalizeUrls";
10
+ import { stripTrackingParams } from "../sdk/urlUtils";
11
+ import { DEFAULT_DEFERRED_TRIGGER, type DeferredTrigger } from "./deferredTrigger";
7
12
  import { findPageByPath, loadBlocks } from "./loader";
8
13
  import { getOnBeforeResolveProps, getSection, registerOnBeforeResolveProps } from "./registry";
9
14
  import {
@@ -109,6 +114,34 @@ export interface AsyncRenderingConfig {
109
114
  * @default true
110
115
  */
111
116
  respectCmsLazy: boolean;
117
+ /**
118
+ * When a deferred (⚡) section fetches its real markup on the client.
119
+ *
120
+ * `"intersection"` (default) waits for the skeleton to come within 300px of
121
+ * the viewport. `"load"` fetches as soon as the wrapper mounts — the
122
+ * behaviour Deco on Fresh gets from `DispatchAsyncRender`'s
123
+ * `partialTriggerMode: "load"`, where the page ships a light skeleton and
124
+ * then materializes every deferred section right after hydration.
125
+ *
126
+ * Sites migrating from Fresh generally want `"load"`: under `"intersection"`
127
+ * alone, everything below the fold does not exist until the user scrolls, so
128
+ * the document stays short and below-the-fold analytics impressions are lost.
129
+ * The cost is a request burst — every deferred section POSTs in the same
130
+ * commit, on load and on each SPA navigation.
131
+ *
132
+ * Read on the CLIENT, so it must be set from a module the browser bundle also
133
+ * loads (normally `setup.ts`, imported from `router.tsx`). Setting it from
134
+ * server-only code leaves the client on `"intersection"` with no warning.
135
+ * Only `@decocms/tanstack` reads it; a no-op in `@decocms/nextjs`.
136
+ *
137
+ * Optional on purpose. `setAsyncRenderingConfig()` always fills it, so the
138
+ * stored config never actually lacks it — but this interface is exported from
139
+ * `@decocms/blocks/cms`, and a required field would break the typecheck of
140
+ * anyone outside the package who builds an `AsyncRenderingConfig` literal.
141
+ * The only sanctioned reader, `getDeferredTrigger()`, already defaults.
142
+ * @default "intersection"
143
+ */
144
+ deferredTrigger?: DeferredTrigger;
112
145
  /**
113
146
  * Fold threshold: sections at or above this flat index are DEFERRED
114
147
  * (rendered as a skeleton and loaded on scroll), so their resolved props are
@@ -189,12 +222,15 @@ export function setAsyncRenderingConfig(config?: {
189
222
  foldThreshold?: number;
190
223
  alwaysEager?: string[];
191
224
  respectCmsLazy?: boolean;
225
+ deferredTrigger?: DeferredTrigger;
192
226
  botAwareSeo?: boolean;
193
227
  }): void {
194
228
  const existing = getAsyncConfig();
195
229
  const merged = new Set([...(existing?.alwaysEager ?? []), ...(config?.alwaysEager ?? [])]);
196
230
  G.__deco.asyncConfig = {
197
231
  respectCmsLazy: config?.respectCmsLazy ?? existing?.respectCmsLazy ?? true,
232
+ deferredTrigger:
233
+ config?.deferredTrigger ?? existing?.deferredTrigger ?? DEFAULT_DEFERRED_TRIGGER,
198
234
  foldThreshold: config?.foldThreshold ?? existing?.foldThreshold ?? DEFAULT_FOLD_THRESHOLD,
199
235
  alwaysEager: merged,
200
236
  botAwareSeo: config?.botAwareSeo ?? existing?.botAwareSeo ?? false,
@@ -243,15 +279,40 @@ function isNeverDeferSection(key: string): boolean {
243
279
  return (G.__deco.neverDeferSectionKeys as Set<string> | undefined)?.has(key) ?? false;
244
280
  }
245
281
 
282
+ // ---------------------------------------------------------------------------
283
+ // Permanent alwaysDefer section registry
284
+ // ---------------------------------------------------------------------------
285
+
286
+ /**
287
+ * Register sections that declared `export const deferred = true`.
288
+ * These sections are ALWAYS deferred (rendered client-side on scroll),
289
+ * independent of the global `respectCmsLazy` config — the per-section opt-in
290
+ * for async-rendering a single heavy section (e.g. a PLP grid) without
291
+ * turning on deferral site-wide. Bots stay eager via the `isBotReq`
292
+ * short-circuit in {@link shouldDeferSection}.
293
+ */
294
+ export function registerAlwaysDeferSections(keys: string[]): void {
295
+ G.__deco.alwaysDeferSectionKeys ??= new Set();
296
+ const set: Set<string> = G.__deco.alwaysDeferSectionKeys;
297
+ for (const k of keys) set.add(k);
298
+ }
299
+
300
+ function isAlwaysDeferSection(key: string): boolean {
301
+ return (G.__deco.alwaysDeferSectionKeys as Set<string> | undefined)?.has(key) ?? false;
302
+ }
303
+
246
304
  // ---------------------------------------------------------------------------
247
305
  // Deferred rawProps cache — keeps rawProps server-side to trim HTML payload
248
306
  // ---------------------------------------------------------------------------
249
307
 
250
308
  const DEFERRED_PROPS_TTL = 120_000; // 2 minutes
251
- const deferredRawPropsCache = new Map<string, { rawProps: Record<string, unknown>; ts: number }>();
309
+ const deferredRawPropsCache = createCacheStore<{ rawProps: Record<string, unknown>; ts: number }>(
310
+ "deferred-props",
311
+ 500,
312
+ );
252
313
 
253
314
  function deferredPropsCacheKey(pagePath: string, component: string, index: number): string {
254
- return `${pagePath}::${component}::${index}`;
315
+ return deferredRawPropsCache.key(`${pagePath}::${component}::${index}`);
255
316
  }
256
317
 
257
318
  export function cacheDeferredRawProps(
@@ -261,15 +322,17 @@ export function cacheDeferredRawProps(
261
322
  rawProps: Record<string, unknown>,
262
323
  ): void {
263
324
  const key = deferredPropsCacheKey(pagePath, component, index);
264
- deferredRawPropsCache.set(key, { rawProps, ts: Date.now() });
325
+ deferredRawPropsCache.set(key, { rawProps, ts: Date.now() }, Date.now() + DEFERRED_PROPS_TTL);
326
+ }
265
327
 
266
- // Lazy eviction: remove expired entries when cache grows
267
- if (deferredRawPropsCache.size > 500) {
268
- const now = Date.now();
269
- for (const [k, v] of deferredRawPropsCache) {
270
- if (now - v.ts > DEFERRED_PROPS_TTL) deferredRawPropsCache.delete(k);
271
- }
272
- }
328
+ /** Async form used when a deferred request may run in a different isolate. */
329
+ export async function readDeferredRawProps(
330
+ pagePath: string,
331
+ component: string,
332
+ index: number,
333
+ ): Promise<Record<string, unknown> | null> {
334
+ const entry = await deferredRawPropsCache.read(deferredPropsCacheKey(pagePath, component, index));
335
+ return entry?.rawProps ?? null;
273
336
  }
274
337
 
275
338
  export function getDeferredRawProps(
@@ -287,9 +350,35 @@ export function getDeferredRawProps(
287
350
  // Bot detection — bots always receive fully eager pages for SEO
288
351
  // ---------------------------------------------------------------------------
289
352
 
290
- const botPatterns: RegExp[] = [
291
- /bot|crawl|spider|slurp|facebookexternalhit|mediapartners|google|bing|yandex|baidu|duckduck|teoma|ia_archiver|semrush|ahrefs|lighthouse/i,
292
- ];
353
+ /**
354
+ * User-Agent substrings that classify a request as a bot.
355
+ *
356
+ * Exported as data, not just baked into the regex, because the CDN cache rules
357
+ * have to bypass exactly the same requests this list makes eager — see
358
+ * `@decocms/blocks-cli/scripts/cdn-rules.ts`. Two hand-maintained copies would
359
+ * drift, and the failure mode is a crawler's eager HTML (~10x larger) being
360
+ * served to humans from the CDN, or the deferred one being served to Google.
361
+ */
362
+ export const BOT_UA_SUBSTRINGS = [
363
+ "bot",
364
+ "crawl",
365
+ "spider",
366
+ "slurp",
367
+ "facebookexternalhit",
368
+ "mediapartners",
369
+ "google",
370
+ "bing",
371
+ "yandex",
372
+ "baidu",
373
+ "duckduck",
374
+ "teoma",
375
+ "ia_archiver",
376
+ "semrush",
377
+ "ahrefs",
378
+ "lighthouse",
379
+ ] as const;
380
+
381
+ const botPatterns: RegExp[] = [new RegExp(BOT_UA_SUBSTRINGS.join("|"), "i")];
293
382
 
294
383
  /**
295
384
  * Add a custom bot detection regex.
@@ -339,9 +428,10 @@ function hasForceEagerParam(ctx?: MatcherContext): boolean {
339
428
  * (`image`/`script`/`style`/`font`) do not — navigations stay deferred because
340
429
  * they CAN hydrate and resolve deferred sections. SPA navigations (TanStack
341
430
  * `<Link>` → `/_serverFn`) also send `empty` but set `isClientNavigation`, and
342
- * are excluded here so page-SEO commerce loaders stay off for humans
343
- * (decocms/blocks#286); their sections already render eagerly via the
344
- * `!isClientNav` branch of the `useAsync` gate.
431
+ * are excluded here on both counts: page-SEO commerce loaders stay off for
432
+ * humans (decocms/blocks#286), and their sections stay deferred, because a
433
+ * client nav renders through `DecoPageRenderer` and therefore CAN resolve a
434
+ * deferred section on scroll — unlike a real AJAX consumer.
345
435
  *
346
436
  * Like {@link hasForceEagerParam}, this must stay in lock-step with the edge
347
437
  * cache key: `workerEntry` keys `Sec-Fetch-Dest: empty` page requests into a
@@ -398,11 +488,15 @@ export interface MatcherContext {
398
488
  */
399
489
  flags?: StoredFlag[];
400
490
  /**
401
- * Client-side (SPA) navigation via TanStack `<Link>`. Disables section
402
- * deferral: deferral is a streaming-SSR optimization, but a client nav
403
- * receives the server-fn JSON in one shot, so deferral adds a round-trip +
404
- * skeleton with no benefit (and breaks loaders that need per-request app
405
- * context — see decocms/blocks#277). Set by the route loaders.
491
+ * Client-side (SPA) navigation via TanStack `<Link>`. Set by the route
492
+ * loaders, where the incoming request URL is the `/_serverFn/...` endpoint
493
+ * rather than the page being navigated to.
494
+ *
495
+ * Consumed by `derivePageUrl` (rebuilding the real page URL, #280) and by
496
+ * {@link isProgrammaticFetch} (a SPA nav sends `Sec-Fetch-Dest: empty` but is
497
+ * NOT an AJAX consumer). It deliberately does NOT affect section deferral —
498
+ * a TanStack route loader is blocking, so eager-resolving below-fold sections
499
+ * on client nav stalls the whole transition. See `resolveDecoPageImpl`.
406
500
  */
407
501
  isClientNavigation?: boolean;
408
502
  }
@@ -736,21 +830,20 @@ function evaluateVariantRule(
736
830
  // production concern (previews aren't cached), so skipping it here is fine.
737
831
  if (!meta || hasMatchersOverride(ctx)) return evaluateMatcher(rule, ctx);
738
832
 
739
- // Reuse a decision already made this request so every resolve pass (page,
740
- // shallow section-key, deferred) selects the same variant.
741
- const already = ctx.flags?.find((f) => f.name === meta.name && f.pct === meta.pct);
742
- if (already) return already.value;
743
-
744
- const stored = parseSegmentCookie(ctx.cookies?.[SEGMENT_COOKIE]).find(
745
- (f) => f.name === meta.name,
746
- );
747
- // pct === -1 marks a classic-deco segment without a fingerprint — honor it
748
- // (stay sticky) instead of re-rolling. A stale fingerprint re-rolls.
749
- const useStored = stored && (stored.pct === -1 || stored.pct === meta.pct);
750
- const value = useStored ? stored.value : Math.random() < meta.traffic;
751
-
752
- ctx.flags?.push({ name: meta.name, value, pct: meta.pct });
753
- return value;
833
+ // Shared with sdk/experiments.ts' N-way resolution — same reuse / stay-sticky
834
+ // / re-roll precedence, so the two assignment paths cannot drift. This path
835
+ // keeps its own `trafficToPct` fingerprint: swapping it for the experiment
836
+ // weight hash would re-roll every live visitor on the next deploy.
837
+ return stickyDecide<boolean>({
838
+ name: meta.name,
839
+ fingerprint: meta.pct,
840
+ recorded: ctx.flags,
841
+ stored: parseSegmentCookie(ctx.cookies?.[SEGMENT_COOKIE]),
842
+ roll: () => Math.random() < meta.traffic,
843
+ // A matcher decision is always boolean; a string here means an experiment
844
+ // took the same cookie slot. Re-roll rather than coerce a variant id.
845
+ accepts: (v) => typeof v === "boolean",
846
+ }).value;
754
847
  }
755
848
 
756
849
  // ---------------------------------------------------------------------------
@@ -815,8 +908,38 @@ async function internalResolve(value: unknown, rctx: ResolveContext): Promise<un
815
908
 
816
909
  const childCtx: ResolveContext = { ...rctx, depth: rctx.depth + 1 };
817
910
 
818
- // "resolved" short-circuit
819
- if (resolveType === "resolved") return obj.data ?? null;
911
+ // ── `asResolved` ─────────────────────────────────────────────────────────
912
+ //
913
+ // `{ __resolveType: "resolved", data }` hands `data` back untouched — the
914
+ // caller is telling us it is already resolved.
915
+ //
916
+ // With `deferred: true` it instead becomes a THUNK, and `data` is not walked
917
+ // at all during the page pass. That is the point: the CMS resolver is
918
+ // recursive and resolves every `__resolveType` it finds in a section's props,
919
+ // including branches the section will not render. Measured on a real store, a
920
+ // PDP's `notFoundSections` — the 404 fallback — carried a shelf whose
921
+ // `products` was a full-text search: 1703ms of the EAGER critical path of
922
+ // EVERY product page, with the result thrown away. Same shape applies to tab
923
+ // content, modal content and unmatched A/B branches.
924
+ //
925
+ // The thunk closes over `childCtx`, so resolving it later still sees THIS
926
+ // request: cookies, UA and url reach the matchers, and `rctx.memo` dedupes
927
+ // named-block references the page already resolved. It does NOT dedupe
928
+ // commerce loaders — those are keyed by their own cache layer, not the memo
929
+ // (see the "Named block reference (memoized)" branch), so a deferred prop
930
+ // pointing at the same loader as a rendered one still calls it twice.
931
+ //
932
+ // HAZARD, and it is why this is opt-in per prop: a thunk cannot be
933
+ // serialized. If a section defers a prop and never calls it, the prop reaches
934
+ // the client as `undefined` (JSON.stringify drops functions). Defer only what
935
+ // the section itself resolves, and only on the branch that needs it.
936
+ if (resolveType === "resolved") {
937
+ if (obj.deferred === true) {
938
+ const raw = obj.data;
939
+ return () => internalResolve(raw, childCtx);
940
+ }
941
+ return obj.data ?? null;
942
+ }
820
943
 
821
944
  // Lazy section wrapper — unwrap single inner section
822
945
  if (resolveType === WELL_KNOWN_TYPES.LAZY) {
@@ -872,21 +995,35 @@ async function internalResolve(value: unknown, rctx: ResolveContext): Promise<un
872
995
  resolvedProps.__pagePath = rctx.matcherCtx.path;
873
996
  }
874
997
  if (rctx.matcherCtx.url) {
875
- resolvedProps.__pageUrl = rctx.matcherCtx.url;
998
+ // Strip tracking params before anything here reaches props.
999
+ //
1000
+ // The comment this replaces claimed the enrichment was "safe re: cache
1001
+ // fragmentation" because commerce loaders run without a framework-level
1002
+ // cache. That was wrong — `getCommerceLoader()` returns the
1003
+ // `createCachedLoader`-wrapped functions, whose default keyFn hashes
1004
+ // exactly these props — so a `?utm_source`/`gclid`/`srsltid` minted a
1005
+ // fresh cache entry and made every paid-traffic landing a permanent cold
1006
+ // miss. Measured on a production storefront: 0.2–1.5% hit rate on the
1007
+ // default keyFn vs 73.5% on a loader that hand-rolled a key excluding it.
1008
+ //
1009
+ // Stripping here rather than in the keyFn covers `__pageUrl` and the
1010
+ // param spread below in one place, and matches how the edge cache key is
1011
+ // already normalized in workerEntry. No loader reads tracking params.
1012
+ //
1013
+ // Deliberately does NOT drop `__pageUrl`/`__pagePath` themselves: on a
1014
+ // PDP the path IS the product identity (the CMS block leaves `slug`
1015
+ // null) and on a PLP the query carries the facets. Dropping them would
1016
+ // merge distinct results onto one entry and serve wrong content.
1017
+ const pageUrl = stripTrackingParams(rctx.matcherCtx.url);
1018
+ resolvedProps.__pageUrl = pageUrl;
876
1019
  // Auto-inject URL search params as top-level props so loaders that
877
1020
  // expect `props.skuId` / `props.q` / `props.page` (the apps-start
878
1021
  // canonical shape) get them populated on direct entry (Google
879
1022
  // Shopping deep links, paid ads, email campaigns). Existing values
880
1023
  // from the CMS block win — URL params are a fallback, not an
881
1024
  // override.
882
- //
883
- // Safe re: cache fragmentation: commerce loaders run through this
884
- // path without a framework-level cache (the section/page cache
885
- // layer hashes section.props BEFORE this enrichment in
886
- // sectionLoaders.ts), so adding query params here does not
887
- // fragment any cache key.
888
- if (URL.canParse(rctx.matcherCtx.url)) {
889
- const url = new URL(rctx.matcherCtx.url);
1025
+ if (URL.canParse(pageUrl)) {
1026
+ const url = new URL(pageUrl);
890
1027
  for (const [k, v] of url.searchParams.entries()) {
891
1028
  if (resolvedProps[k] !== undefined) continue;
892
1029
  // `page` is skipped on purpose (#391): loaders that read `page`
@@ -910,7 +1047,7 @@ async function internalResolve(value: unknown, rctx: ResolveContext): Promise<un
910
1047
  // upstream is wrong — surface it so the caller can fix it.
911
1048
  console.warn(
912
1049
  `[CMS] malformed matcherCtx.url for "${resolveType}"; ` +
913
- `skipping query-param injection: ${rctx.matcherCtx.url}`,
1050
+ `skipping query-param injection: ${pageUrl}`,
914
1051
  );
915
1052
  }
916
1053
  }
@@ -1049,11 +1186,38 @@ interface ResolvedSectionsCache {
1049
1186
  expiresAt: number;
1050
1187
  }
1051
1188
 
1052
- const resolvedLayoutCache = new Map<string, ResolvedSectionsCache>();
1189
+ const resolvedLayoutCache = createCacheStore<ResolvedSectionsCache>("resolved-layouts");
1053
1190
  const resolvedLayoutInflight = new Map<string, Promise<ResolvedSection[]>>();
1054
1191
 
1055
- function getCachedResolvedLayout(blockKey: string): ResolvedSection[] | null {
1056
- const entry = resolvedLayoutCache.get(blockKey);
1192
+ /**
1193
+ * Cache key for a resolved layout block, segmented by DEVICE.
1194
+ *
1195
+ * The key used to be the component path alone, and that made the cache unusable
1196
+ * for any site whose Header/Footer takes a per-request device prop: the first
1197
+ * visitor's variant was served to everyone for the whole TTL (mobile header on
1198
+ * desktop and vice-versa). The only escape was to leave those sections out of
1199
+ * `registerLayoutSections` entirely — which is what a real store did, and it
1200
+ * then re-resolved Header and Footer on every single page and navigation.
1201
+ *
1202
+ * Device is the right default axis because it is the one thing the framework
1203
+ * itself injects into every section (`sectionLoaderContext` → `detectDevice`),
1204
+ * so a layout section can depend on it WITHOUT the site opting into anything.
1205
+ * A layout that does not vary by device just gets up to 3 identical entries —
1206
+ * a bounded, negligible cost against silently serving the wrong markup.
1207
+ *
1208
+ * Anything else a layout varies on (region, sales channel, locale) is
1209
+ * site-specific and NOT covered here: those sections should stay out of
1210
+ * `registerLayoutSections` until there is a demonstrated need for a `vary`
1211
+ * hook. Adding axes nobody asked for only shrinks the hit rate.
1212
+ *
1213
+ * Exported for unit testing.
1214
+ */
1215
+ export function layoutCacheKey(blockKey: string, matcherCtx?: MatcherContext): string {
1216
+ return `${blockKey}::${detectDevice(matcherCtx?.userAgent ?? "")}`;
1217
+ }
1218
+
1219
+ async function getCachedResolvedLayout(blockKey: string): Promise<ResolvedSection[] | null> {
1220
+ const entry = await resolvedLayoutCache.read(blockKey);
1057
1221
  if (!entry) return null;
1058
1222
  if (Date.now() > entry.expiresAt) {
1059
1223
  resolvedLayoutCache.delete(blockKey);
@@ -1063,10 +1227,14 @@ function getCachedResolvedLayout(blockKey: string): ResolvedSection[] | null {
1063
1227
  }
1064
1228
 
1065
1229
  function setCachedResolvedLayout(blockKey: string, sections: ResolvedSection[]): void {
1066
- resolvedLayoutCache.set(blockKey, {
1067
- sections,
1068
- expiresAt: Date.now() + RESOLVE_CACHE_TTL,
1069
- });
1230
+ resolvedLayoutCache.set(
1231
+ blockKey,
1232
+ {
1233
+ sections,
1234
+ expiresAt: Date.now() + RESOLVE_CACHE_TTL,
1235
+ },
1236
+ Date.now() + RESOLVE_CACHE_TTL,
1237
+ );
1070
1238
  }
1071
1239
 
1072
1240
  /**
@@ -1475,6 +1643,15 @@ function isCmsDeferralWrapped(section: unknown, matcherCtx?: MatcherContext): bo
1475
1643
  * then they can only force a NON-⚡ section eager — they never override the
1476
1644
  * editor's ⚡ choice.
1477
1645
  *
1646
+ * Because deferral now applies to client (SPA) navigations too, a ⚡ section is
1647
+ * resolved on a SECOND server hop (`loadDeferredSection`) in both cases. That
1648
+ * hop rebuilds MatcherContext from the real request, but it cannot reconstruct
1649
+ * "which branch of the page renders at all" — so a *gate* section (one whose
1650
+ * loader picks between `children`/`fallback`, e.g. a combined PDP/PLP route)
1651
+ * must be left un-⚡ in the admin. There is deliberately no code-level override
1652
+ * for this: `neverDefer`/`alwaysEager` sit below the admin check and cannot win
1653
+ * against an explicit editorial ⚡ (see decocms/blocks#277).
1654
+ *
1478
1655
  * Exported for unit testing.
1479
1656
  */
1480
1657
  export function shouldDeferSection(
@@ -1497,6 +1674,12 @@ export function shouldDeferSection(
1497
1674
  const finalKey = resolveFinalSectionKey(section, matcherCtx);
1498
1675
  if (!finalKey) return false;
1499
1676
 
1677
+ // ── PER-SECTION FORCE-DEFER (`export const deferred = true`) ───────────────
1678
+ // Explicit code-level opt-in to defer one section regardless of the global
1679
+ // `respectCmsLazy` config — lets a site async-render a single heavy section
1680
+ // without a site-wide skeleton sweep. Bots already returned eager above.
1681
+ if (isAlwaysDeferSection(finalKey)) return true;
1682
+
1500
1683
  // ── ADMIN IS THE SOURCE OF TRUTH ──────────────────────────────────────────
1501
1684
  // If the editor marked the section ⚡ (wrapped in CMS Lazy/Deferred at any
1502
1685
  // nesting level, including multivariate flags), it is deferred —
@@ -1686,6 +1869,65 @@ export async function resolveSectionsList(
1686
1869
  return [];
1687
1870
  }
1688
1871
 
1872
+ // ---------------------------------------------------------------------------
1873
+ // Deferred props (`asResolved`)
1874
+ // ---------------------------------------------------------------------------
1875
+
1876
+ /** A prop deferred with `asResolved(value, true)`: call it to resolve. */
1877
+ export type Deferred<T> = () => Promise<T>;
1878
+
1879
+ /**
1880
+ * Mark a prop as already-resolved, or defer its resolution to the section.
1881
+ *
1882
+ * Use it from a section's `onBeforeResolveProps`, which runs on the RAW CMS
1883
+ * props before the resolver walks them:
1884
+ *
1885
+ * ```ts
1886
+ * export const onBeforeResolveProps = (props: Props) => ({
1887
+ * ...props,
1888
+ * // The 404 fallback: only the branch that renders it should pay for it.
1889
+ * notFoundSections: asResolved(props.notFoundSections, true),
1890
+ * })
1891
+ *
1892
+ * export const loader = async (props: Props) => {
1893
+ * if (props.page) return { ...props, notFoundSections: [] }
1894
+ * return { ...props, notFoundSections: await resolveDeferred(props.notFoundSections) }
1895
+ * }
1896
+ * ```
1897
+ *
1898
+ * - `asResolved(v)` — hand `v` back untouched; the resolver does not walk it.
1899
+ * - `asResolved(v, true)` — the section receives a {@link Deferred} thunk and
1900
+ * decides whether to pay for it.
1901
+ *
1902
+ * A deferred prop that is never called reaches the client as `undefined`: a
1903
+ * thunk cannot be serialized. That is deliberate — it is what keeps the unused
1904
+ * branch out of the hydration payload too — but it means you must resolve it on
1905
+ * the branch that renders it.
1906
+ */
1907
+ export function asResolved<T>(value: T, defer?: boolean): T {
1908
+ return {
1909
+ __resolveType: "resolved",
1910
+ data: value,
1911
+ ...(defer ? { deferred: true } : {}),
1912
+ } as unknown as T;
1913
+ }
1914
+
1915
+ /** True when a prop came through as a {@link Deferred} thunk. */
1916
+ export function isDeferred<T>(value: unknown): value is Deferred<T> {
1917
+ return typeof value === "function";
1918
+ }
1919
+
1920
+ /**
1921
+ * Resolve a possibly-deferred prop.
1922
+ *
1923
+ * Tolerant of a plain value, so a section reads the same whether the prop was
1924
+ * deferred, marked already-resolved, or left alone — and so the admin preview
1925
+ * (which does not run `onBeforeResolveProps`) keeps working.
1926
+ */
1927
+ export async function resolveDeferred<T>(value: Deferred<T> | T): Promise<T> {
1928
+ return isDeferred<T>(value) ? await value() : (value as T);
1929
+ }
1930
+
1689
1931
  // ---------------------------------------------------------------------------
1690
1932
  // Page-level SEO — extracted from registered SEO sections after resolution
1691
1933
  // ---------------------------------------------------------------------------
@@ -1739,28 +1981,71 @@ function canonicalFromBreadcrumb(breadcrumb: unknown): string | undefined {
1739
1981
  }
1740
1982
 
1741
1983
  /**
1742
- * Shallow-prune a commerce `jsonLD` before emitting it as structured data.
1984
+ * Shallow-prune a PDP `jsonLD` before emitting it as structured data.
1743
1985
  * Clones only when a prune option is set (the common path emits as-is), so a
1744
1986
  * jsonLD shared with a body section is never mutated out from under it.
1745
1987
  */
1746
1988
  function pruneCommerceJsonLD(
1747
1989
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1748
1990
  jsonLD: Record<string, any>,
1749
- opts: { removeVideos: boolean; omitVariants: boolean },
1991
+ opts: { omitVariants: boolean },
1750
1992
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1751
1993
  ): Record<string, any> {
1752
- if (!opts.removeVideos && !opts.omitVariants) return jsonLD;
1994
+ if (!opts.omitVariants || !jsonLD.product?.isVariantOf?.hasVariant) return jsonLD;
1753
1995
  const clone = structuredClone(jsonLD);
1754
- if (opts.removeVideos && Array.isArray(clone.products)) {
1755
- for (const product of clone.products) {
1756
- product.video = undefined;
1757
- for (const variant of product.isVariantOf?.hasVariant ?? []) variant.video = undefined;
1758
- }
1996
+ clone.product.isVariantOf.hasVariant = [];
1997
+ return clone;
1998
+ }
1999
+
2000
+ /**
2001
+ * schema.org structured data for a listing page: an `ItemList` of
2002
+ * position/url/name (what search engines read on category pages) plus the
2003
+ * `BreadcrumbList`. Emitting the resolved ProductListingPage itself is not
2004
+ * schema.org (no such type, no `@context`) and inlines every product with
2005
+ * variants/specs/images — multiple MB per page, in the HTML *and* in the
2006
+ * serialized route data, which pushes Workers past their memory limit.
2007
+ */
2008
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2009
+ function plpStructuredData(plp: Record<string, any>): Record<string, unknown>[] {
2010
+ // Canonical product URL first: `url` is the SKU URL (`/p?skuId=N`), which
2011
+ // canonicalises elsewhere. Items without a URL are dropped (Google requires
2012
+ // `url` on summary-page items) before numbering, so positions stay contiguous.
2013
+ const itemListElement = (plp.products as any[]) // eslint-disable-line @typescript-eslint/no-explicit-any
2014
+ .map((p) => ({ url: p.isVariantOf?.url ?? p.url, name: p.isVariantOf?.name ?? p.name }))
2015
+ .filter((item) => item.url)
2016
+ .map((item, i) => ({ "@type": "ListItem", position: i + 1, ...item }));
2017
+ const out: Record<string, unknown>[] = [
2018
+ {
2019
+ "@context": "https://schema.org",
2020
+ "@type": "ItemList",
2021
+ numberOfItems: itemListElement.length,
2022
+ itemListElement,
2023
+ },
2024
+ ];
2025
+ if (plp.breadcrumb?.itemListElement?.length) {
2026
+ // Loaders emit path-only breadcrumb items (`/a/b`) for in-app links; in
2027
+ // structured data make them absolute, using the products' origin.
2028
+ const origin = originOf(itemListElement[0]?.url) ?? originOf(plp.seo?.canonical);
2029
+ out.push({
2030
+ ...plp.breadcrumb,
2031
+ "@context": "https://schema.org",
2032
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2033
+ itemListElement: plp.breadcrumb.itemListElement.map((el: any) =>
2034
+ origin && typeof el.item === "string" && /^\/(?!\/)/.test(el.item)
2035
+ ? { ...el, item: new URL(el.item, origin).href }
2036
+ : el,
2037
+ ),
2038
+ });
1759
2039
  }
1760
- if (opts.omitVariants && clone.product?.isVariantOf?.hasVariant) {
1761
- clone.product.isVariantOf.hasVariant = [];
2040
+ return out;
2041
+ }
2042
+
2043
+ function originOf(url: unknown): string | undefined {
2044
+ try {
2045
+ return typeof url === "string" ? new URL(url).origin : undefined;
2046
+ } catch {
2047
+ return undefined;
1762
2048
  }
1763
- return clone;
1764
2049
  }
1765
2050
 
1766
2051
  /**
@@ -1772,7 +2057,7 @@ function pruneCommerceJsonLD(
1772
2057
  * ship loaders/types, not sections), so nothing else runs this transform.
1773
2058
  * Without it, PLP/PDP pages whose `page.seo` points at those types emit a
1774
2059
  * <title>/canonical (from top-level override props) but NO schema.org
1775
- * structured data — the casaevideo.com.br/eletroportateis regression.
2060
+ * structured data — the acme.com.br/eletroportateis regression.
1776
2061
  *
1777
2062
  * Manual override fields already read into `seo` always win; this only fills
1778
2063
  * gaps and appends the JSON-LD. The caller guards on `seo.jsonLDs` so a real
@@ -1820,18 +2105,13 @@ function deriveCommerceSeoFromJsonLD(
1820
2105
  // humans only; crawlers (and the `?__deco_ssr=1` audit override) still get it
1821
2106
  // so indexing/rich results are unaffected. An empty page contributes no
1822
2107
  // ItemList regardless.
1823
- const configJsonLD = props.configJsonLD as
1824
- | { ignoreStructuredData?: boolean; removeVideos?: boolean }
1825
- | undefined;
1826
2108
  const ignore = sectionIgnoresStructuredData(props);
1827
2109
  if ((ignore && !isEager) || isEmpty) return;
1828
2110
 
1829
- seo.jsonLDs = [
1830
- pruneCommerceJsonLD(jsonLD, {
1831
- removeVideos: configJsonLD?.removeVideos === true,
1832
- omitVariants: props.omitVariants === true,
1833
- }),
1834
- ];
2111
+ seo.jsonLDs =
2112
+ type === "ProductListingPage"
2113
+ ? plpStructuredData(jsonLD)
2114
+ : [pruneCommerceJsonLD(jsonLD, { omitVariants: props.omitVariants === true })];
1835
2115
  }
1836
2116
 
1837
2117
  /**
@@ -1954,13 +2234,32 @@ async function resolveDecoPageImpl(
1954
2234
  }
1955
2235
 
1956
2236
  const isBotReq = isEagerRequest(matcherCtx);
1957
- // SPA navigation (TanStack <Link>) receives the server-fn JSON in one shot —
1958
- // there is no HTTP streaming, so deferral adds a round-trip + skeleton with
1959
- // no benefit (and breaks loaders that need per-request app context, #277).
1960
- // Resolve everything eagerly on client nav; SSR/bots keep deferral.
1961
- const isClientNav = matcherCtx?.isClientNavigation ?? false;
2237
+ // Deferral applies identically to SSR documents and SPA navigations. A
2238
+ // TanStack route loader is BLOCKING: the router does not commit the
2239
+ // transition until the loader promise settles, so resolving every
2240
+ // below-the-fold section eagerly on client nav freezes the previous page for
2241
+ // as long as the slowest shelf/upstream takes (measured: 2.7s and a 3.4MB
2242
+ // payload on a real PDP — worse than a full reload). Deferral's job is
2243
+ // decoupling first paint from below-fold data, which matters MORE here, not
2244
+ // less.
2245
+ //
2246
+ // #277 (deferred loaders missing per-request app context) is not a reason to
2247
+ // disable deferral on client nav: the deferred second hop is the same
2248
+ // `loadDeferredSection` server fn the SSR path has always used, and it runs
2249
+ // server-side with matcherCtx rebuilt from the real request
2250
+ // (url/path/cookies/request). It may well land in a DIFFERENT isolate — that
2251
+ // is exactly why `reExtractRawProps` exists as the rawProps cache-miss path —
2252
+ // but per-request state is reconstructed from the request either way, so a
2253
+ // client nav is no more exposed than an SSR document already was. A section
2254
+ // whose loader genuinely cannot be resolved on a second hop (e.g. a PDP/PLP
2255
+ // gate that decides what renders at all) must not be marked ⚡ in the admin;
2256
+ // see `shouldDeferSection`.
2257
+ //
2258
+ // `isClientNavigation` is still load-bearing for `derivePageUrl` (duplicate
2259
+ // query params) and for `isProgrammaticFetch` (SPA `Sec-Fetch-Dest: empty`
2260
+ // must not be mistaken for an AJAX call) — it just no longer gates deferral.
1962
2261
  const currentAsyncConfig = getAsyncConfig();
1963
- const useAsync = currentAsyncConfig !== null && !isBotReq && !isClientNav;
2262
+ const useAsync = currentAsyncConfig !== null && !isBotReq;
1964
2263
 
1965
2264
  const eagerResults: (ResolvedSection[] | Promise<ResolvedSection[]>)[] = [];
1966
2265
  const deferredSections: DeferredSection[] = [];
@@ -2040,20 +2339,21 @@ async function resolveDecoPageImpl(
2040
2339
  const layoutKey = isRawSectionLayout(section);
2041
2340
 
2042
2341
  if (layoutKey) {
2043
- const cached = getCachedResolvedLayout(layoutKey);
2342
+ const cacheKey = resolvedLayoutCache.key(layoutCacheKey(layoutKey, rctx.matcherCtx));
2343
+ const cached = await getCachedResolvedLayout(cacheKey);
2044
2344
  if (cached) return cached;
2045
2345
 
2046
- const inflight = resolvedLayoutInflight.get(layoutKey);
2346
+ const inflight = resolvedLayoutInflight.get(cacheKey);
2047
2347
  if (inflight) return inflight;
2048
2348
 
2049
2349
  const p = withInflightTimeout(
2050
2350
  resolveRawSection(section, rctx).then((results) => {
2051
- setCachedResolvedLayout(layoutKey, results);
2351
+ setCachedResolvedLayout(cacheKey, results);
2052
2352
  return results;
2053
2353
  }),
2054
- `resolvedLayout ${layoutKey}`,
2055
- ).finally(() => resolvedLayoutInflight.delete(layoutKey));
2056
- resolvedLayoutInflight.set(layoutKey, p);
2354
+ `resolvedLayout ${cacheKey}`,
2355
+ ).finally(() => resolvedLayoutInflight.delete(cacheKey));
2356
+ resolvedLayoutInflight.set(cacheKey, p);
2057
2357
  return p;
2058
2358
  }
2059
2359
 
@@ -2137,20 +2437,21 @@ export async function resolvePageSections(
2137
2437
  const layoutKey = isRawSectionLayout(section);
2138
2438
 
2139
2439
  if (layoutKey) {
2140
- const cached = getCachedResolvedLayout(layoutKey);
2440
+ const cacheKey = resolvedLayoutCache.key(layoutCacheKey(layoutKey, rctx.matcherCtx));
2441
+ const cached = await getCachedResolvedLayout(cacheKey);
2141
2442
  if (cached) return cached;
2142
2443
 
2143
- const inflight = resolvedLayoutInflight.get(layoutKey);
2444
+ const inflight = resolvedLayoutInflight.get(cacheKey);
2144
2445
  if (inflight) return inflight;
2145
2446
 
2146
2447
  const p = withInflightTimeout(
2147
2448
  resolveRawSection(section, rctx).then((results) => {
2148
- setCachedResolvedLayout(layoutKey, results);
2449
+ setCachedResolvedLayout(cacheKey, results);
2149
2450
  return results;
2150
2451
  }),
2151
- `resolvedLayout ${layoutKey}`,
2152
- ).finally(() => resolvedLayoutInflight.delete(layoutKey));
2153
- resolvedLayoutInflight.set(layoutKey, p);
2452
+ `resolvedLayout ${cacheKey}`,
2453
+ ).finally(() => resolvedLayoutInflight.delete(cacheKey));
2454
+ resolvedLayoutInflight.set(cacheKey, p);
2154
2455
  return p;
2155
2456
  }
2156
2457
 
@@ -2228,7 +2529,7 @@ export async function resolveDeferredSectionFull(
2228
2529
  // rawProps may be stripped from the client payload — resolve from cache or page
2229
2530
  const rawProps =
2230
2531
  ds.rawProps ??
2231
- getDeferredRawProps(pagePath, ds.component, ds.index) ??
2532
+ (await readDeferredRawProps(pagePath, ds.component, ds.index)) ??
2232
2533
  (await reExtractRawProps(pagePath, ds.component, ds.index, matcherCtx));
2233
2534
 
2234
2535
  if (!rawProps) return null;