@decocms/blocks 7.15.0 → 7.15.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decocms/blocks",
3
- "version": "7.15.0",
3
+ "version": "7.15.1",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=24"
@@ -1,8 +1,10 @@
1
1
  import { describe, expect, it } from "vitest";
2
2
  import {
3
3
  registerLayoutSections,
4
+ registerSectionLoader,
4
5
  registerSections,
5
6
  resolveDecoPage,
7
+ runSectionLoaders,
6
8
  setBlocks,
7
9
  unregisterLayoutSections,
8
10
  } from "./index";
@@ -103,6 +105,39 @@ describe("resolveDecoPage — layout section cache does not leak `.index` across
103
105
  }
104
106
  });
105
107
 
108
+ it("does not leak index across sequential requests when the result is already in the TTL cache", async () => {
109
+ // This covers the scenario missing from the concurrent test above:
110
+ // Page A is fully served first (result lands in layoutCache), then Page B
111
+ // arrives and hits the cache — it must get its own index, not Page A's.
112
+ const FOOTER_KEY = "site/sections/SeqCacheFooter.tsx";
113
+
114
+ registerLayoutSections([FOOTER_KEY]);
115
+ registerSectionLoader(FOOTER_KEY, async (props) => props);
116
+
117
+ const req = new Request("https://example.com/");
118
+ const makeSection = (index: number) => ({
119
+ component: FOOTER_KEY,
120
+ props: {},
121
+ key: `${FOOTER_KEY}-${index}`,
122
+ index,
123
+ });
124
+
125
+ try {
126
+ // First request: populate the TTL cache with index 2.
127
+ const [sectionA] = await runSectionLoaders([makeSection(2)], req);
128
+
129
+ // Second request: hits the TTL cache — must get index 7, not 2.
130
+ const [sectionB] = await runSectionLoaders([makeSection(7)], req);
131
+
132
+ expect(sectionA?.index).toBe(2);
133
+ expect(sectionB?.index).toBe(7);
134
+ // Must be separate objects — the cached entry must never carry an index.
135
+ expect(sectionA).not.toBe(sectionB);
136
+ } finally {
137
+ unregisterLayoutSections([FOOTER_KEY]);
138
+ }
139
+ });
140
+
106
141
  it("mechanism check: mutating a shared object in place under concurrent stamping loses one side's index (isolated, framework-independent)", async () => {
107
142
  // This isolates the exact bug mechanism from the diff that shipped in
108
143
  // 6.12.1 and was reverted after the rollback, independent of the CMS
@@ -270,19 +270,26 @@ function resolveLayoutSection(
270
270
  request: Request,
271
271
  ): Promise<ResolvedSection> {
272
272
  const key = section.component;
273
+ const { index } = section;
274
+
275
+ // Re-apply the caller's page-specific index onto a fresh object so the
276
+ // shared cache entry never carries an index from a previous request.
277
+ const withIndex = (s: ResolvedSection): ResolvedSection =>
278
+ index !== undefined ? { ...s, index } : s;
273
279
 
274
280
  const cached = getCachedLayout(key);
275
- if (cached) return Promise.resolve(cached);
281
+ if (cached) return Promise.resolve(withIndex(cached));
276
282
 
277
283
  const existing = layoutInflight.get(key);
278
- if (existing) return existing;
284
+ if (existing) return existing.then(withIndex);
279
285
 
280
286
  const promise = withInflightTimeout(
281
287
  (async () => {
282
288
  const enrichedProps = await loader(section.props as Record<string, unknown>, request);
283
- const enriched = { ...section, props: enrichedProps };
289
+ const { index: _idx, ...sectionWithoutIndex } = section;
290
+ const enriched = { ...sectionWithoutIndex, props: enrichedProps };
284
291
  setCachedLayout(key, enriched);
285
- return enriched;
292
+ return withIndex(enriched);
286
293
  })(),
287
294
  `layoutSection ${key}`,
288
295
  ).finally(() => layoutInflight.delete(key));