@decocms/tanstack 7.48.3 → 7.49.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/tanstack",
3
- "version": "7.48.3",
3
+ "version": "7.49.0",
4
4
  "type": "module",
5
5
  "description": "Deco framework binding for TanStack Start + Cloudflare Workers",
6
6
  "repository": {
@@ -24,9 +24,9 @@
24
24
  "lint:unused": "knip"
25
25
  },
26
26
  "dependencies": {
27
- "@decocms/blocks": "7.48.3",
28
- "@decocms/blocks-admin": "7.48.3",
29
- "@decocms/blocks-cli": "7.48.3",
27
+ "@decocms/blocks": "7.49.0",
28
+ "@decocms/blocks-admin": "7.49.0",
29
+ "@decocms/blocks-cli": "7.49.0",
30
30
  "@deco-cx/warp-node": "^0.3.16",
31
31
  "fast-json-patch": "^3.1.0",
32
32
  "ws": "^8.18.0"
@@ -49,6 +49,7 @@ import {
49
49
  detectCacheProfile,
50
50
  routeCacheDefaults,
51
51
  } from "@decocms/blocks/sdk/cacheHeaders";
52
+ import { takeExperimentAssignments } from "@decocms/blocks/sdk/experiments";
52
53
  import {
53
54
  parseSegmentCookie,
54
55
  SEGMENT_COOKIE,
@@ -116,9 +117,16 @@ const SEGMENT_COOKIE_MAX_AGE = 60 * 60 * 24 * 365;
116
117
  *
117
118
  * `encode: (v) => v` keeps the raw base64 intact — @decocms/apps
118
119
  * OneDollarStats reads the cookie with `atob()` directly.
120
+ *
121
+ * Experiment assignments (`sdk/experiments.ts`) merge in through the same
122
+ * writer rather than setting their own cookie — one `deco_segment`, one
123
+ * Set-Cookie. That is why this runs AFTER the section loaders: CMS matchers
124
+ * decide during page resolution, but an experiment is resolved inside a
125
+ * loader, so persisting before the loaders ran would drop the assignment and
126
+ * the visitor would re-roll on every request.
119
127
  */
120
- function persistFlags(matcherCtx: MatcherContext): StoredFlag[] {
121
- const recorded = matcherCtx.flags ?? [];
128
+ function persistFlags(matcherCtx: MatcherContext, experiments: StoredFlag[] = []): StoredFlag[] {
129
+ const recorded = [...(matcherCtx.flags ?? []), ...experiments];
122
130
  if (!recorded.length) return [];
123
131
 
124
132
  const raw = matcherCtx.cookies?.[SEGMENT_COOKIE];
@@ -188,7 +196,6 @@ async function loadCmsPageInternal(fullPath: string, resolveGlobals: boolean) {
188
196
  };
189
197
  const page = await resolveDecoPage(basePath, matcherCtx);
190
198
  if (!page) return null;
191
- const flags = persistFlags(matcherCtx);
192
199
 
193
200
  const request = new Request(urlWithSearch, {
194
201
  headers: originRequest.headers,
@@ -205,6 +212,10 @@ async function loadCmsPageInternal(fullPath: string, resolveGlobals: boolean) {
205
212
  resolveGlobals ? resolveSiteGlobals(matcherCtx) : Promise.resolve(EMPTY_GLOBALS),
206
213
  ]);
207
214
 
215
+ // After the loaders — a loader-resolved experiment assignment must be in the
216
+ // cookie this response sets. See persistFlags.
217
+ const flags = persistFlags(matcherCtx, takeExperimentAssignments());
218
+
208
219
  // Page sections take precedence over globals — dedupe drops any global
209
220
  // whose component is already rendered by the page.
210
221
  const mergedSections: ResolvedSection[] = [
@@ -329,11 +340,11 @@ export const loadCmsHomePage = createServerFn({ method: "GET" })
329
340
  };
330
341
  const page = await resolveDecoPage("/", matcherCtx);
331
342
  if (!page) return null;
332
- const flags = persistFlags(matcherCtx);
333
343
  const [{ enrichedSections, enrichedSeoSection }, globals] = await Promise.all([
334
344
  runSectionLoadersWithSeo(page.resolvedSections, page.seoSection, request),
335
345
  resolveGlobals ? resolveSiteGlobals(matcherCtx) : Promise.resolve(EMPTY_GLOBALS),
336
346
  ]);
347
+ const flags = persistFlags(matcherCtx, takeExperimentAssignments());
337
348
 
338
349
  const mergedSections: ResolvedSection[] = [
339
350
  ...dedupeGlobals(globals.resolvedSections, enrichedSections),
@@ -1996,7 +1996,7 @@ export function createDecoWorkerEntry(
1996
1996
 
1997
1997
  // Merge site-wide SEO defaults into seo props
1998
1998
  const blocks = loadBlocks();
1999
- const site = blocks["Site"] as Record<string, unknown> | undefined;
1999
+ const site = (blocks["Site"] ?? blocks["site"]) as Record<string, unknown> | undefined;
2000
2000
  const fullSiteSeo = (site?.seo as Record<string, unknown>) ?? {};
2001
2001
 
2002
2002
  // When SeoV2 loader ran, use its output as base (preserves key order)