@decocms/blocks 7.15.0 → 7.16.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decocms/blocks",
3
- "version": "7.15.0",
3
+ "version": "7.16.0",
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));
package/src/sdk/otel.ts CHANGED
@@ -99,6 +99,23 @@ import { RequestContext } from "./requestContext";
99
99
  // ---------------------------------------------------------------------------
100
100
 
101
101
  export interface OtelOptions {
102
+ /**
103
+ * When `true`, skips all observability exporters (AE, OTLP metrics,
104
+ * logs, traces). Overridden by the env var.
105
+ */
106
+ disabled?: boolean;
107
+ /**
108
+ * Env var name holding the tri-state observability switch. Values:
109
+ * - `"on"` → force enable (even in local dev)
110
+ * - `"off"` → force disable
111
+ * - unset → auto: enabled in real deploys, disabled in local
112
+ *
113
+ * Local is detected by the absence of `CF_VERSION_METADATA` (a binding
114
+ * that only exists in production/preview Cloudflare deploys).
115
+ *
116
+ * Defaults to `"DECO_OTEL"`.
117
+ */
118
+ envVar?: string;
102
119
  /** Logical service name. Falls back to `env.DECO_SITE_NAME`, then "deco-site". */
103
120
  serviceName?: string;
104
121
  /** Env var name holding the AE binding. Defaults to `"DECO_METRICS"`. */
@@ -624,6 +641,18 @@ function bootObservability(opts: OtelOptions, env: Record<string, unknown>): voi
624
641
  const state = getBootState();
625
642
  if (state.booted) return;
626
643
 
644
+ // CF_VERSION_METADATA is only present in real (production/preview) deploys;
645
+ // wrangler dev never sets it, making it a reliable local-dev signal.
646
+ const mode = env[opts.envVar ?? "DECO_OTEL"];
647
+ const isLocal = !env.CF_VERSION_METADATA;
648
+ const isDisabled =
649
+ mode === "off" ||
650
+ (mode !== "on" && (opts.disabled || isLocal));
651
+ if (isDisabled) {
652
+ state.booted = true;
653
+ return;
654
+ }
655
+
627
656
  // Capture the original console.warn BEFORE patchConsole() runs. The onError
628
657
  // callbacks below need a direct channel to console that bypasses the logger
629
658
  // to avoid routing exporter-level warnings back through the OTLP adapter