diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 90468991e..16316f97a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,7 +2,7 @@ ## Release channels -This repository ships on two channels: +This repository publishes on two channels: | Channel | Branch | Example version | JSR resolution | |---------|--------|-----------------|----------------| diff --git a/deno.json b/deno.json index f4d060533..1b1da38cf 100644 --- a/deno.json +++ b/deno.json @@ -1,6 +1,6 @@ { "name": "@deco/deco", - "version": "1.197.0", + "version": "1.197.1-next.2", "lock": false, "nodeModulesDir": "auto", "exports": { diff --git a/dev/deno.json b/dev/deno.json index 15843f936..8fe98eff4 100644 --- a/dev/deno.json +++ b/dev/deno.json @@ -1,6 +1,6 @@ { "name": "@deco/dev", - "version": "1.197.0", + "version": "1.197.1-next.2", "exports": { "./tailwind": "./tailwind.ts" }, diff --git a/runtime/middleware.ts b/runtime/middleware.ts index aa9528f12..177756e16 100644 --- a/runtime/middleware.ts +++ b/runtime/middleware.ts @@ -390,27 +390,24 @@ export const middlewareFor = ( ); const segment = tryOrDefault(() => JSON.parse(cookieSegment), {}); - const active = new Set(segment.active || []); - const inactiveDrawn = new Set(segment.inactiveDrawn || []); + // Track only the `active` set. The previous `inactiveDrawn` set was + // write-only state — never read by any matcher logic — and its growth + // across pages was the main reason `deco_segment` got rewritten on + // almost every request, tripping the Set-Cookie kill-switch below and + // making HTML uncacheable. Removing it lets cohort assignment stick. + const previousActive = [...new Set(segment.active || [])].sort(); + const active = new Set(previousActive); for (const flag of ctx.var.flags) { - if (flag.isSegment) { - if (flag.value) { - active.add(flag.name); - inactiveDrawn.delete(flag.name); - } else { - active.delete(flag.name); - inactiveDrawn.add(flag.name); - } - } + if (!flag.isSegment) continue; + if (flag.value) active.add(flag.name); + else active.delete(flag.name); } - const newSegment = { - active: [...active].sort(), - inactiveDrawn: [...inactiveDrawn].sort(), - }; - const value = JSON.stringify(newSegment); - const hasFlags = active.size > 0 || inactiveDrawn.size > 0; - - if (hasFlags && cookieSegment !== value) { + const newActive = [...active].sort(); + const activeChanged = + JSON.stringify(previousActive) !== JSON.stringify(newActive); + + if (active.size > 0 && activeChanged) { + const value = JSON.stringify({ active: newActive }); const date = new Date(); date.setTime(date.getTime() + 30 * 24 * 60 * 60 * 1000); // 1 month setCookie( diff --git a/runtime/routes/_meta.ts b/runtime/routes/_meta.ts index d4caaee80..c83be5673 100644 --- a/runtime/routes/_meta.ts +++ b/runtime/routes/_meta.ts @@ -21,7 +21,8 @@ export const handler = createHandler(async (ctx) => { return new Response(JSON.stringify(value), { headers: { "Content-Type": "application/json", - "cache-control": "must-revalidate", + "cache-control": + "public, max-age=60, s-maxage=60, stale-while-revalidate=300, must-revalidate", etag, ...allowCorsFor(ctx.req.raw), }, diff --git a/scripts/deno.json b/scripts/deno.json index a0d56344c..960670403 100644 --- a/scripts/deno.json +++ b/scripts/deno.json @@ -1,6 +1,6 @@ { "name": "@deco/scripts", - "version": "1.197.0", + "version": "1.197.1-next.2", "exports": { "./release": "./release.ts", "./update": "./update.run.ts",