Skip to content

feat: @decocms/nextjs for v8: draft proxy and pages helpers, its own draft names and Studio origins, withDeco() and a platform-neutral image loader - #697

Closed
tlgimenes wants to merge 1 commit into
feat/tanstack-v8from
feat/nextjs-v8
Closed

tlgimenes wants to merge 1 commit into
feat/tanstack-v8from
feat/nextjs-v8

Conversation

@tlgimenes

@tlgimenes tlgimenes commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #696 (feat/tanstack-v8). Adds packages/nextjs, @decocms/nextjs for v8: small helpers for any Next.js App Router app, with no hosting assumptions (no CDN, ISR or platform rules). The site calls them from its own proxy, layout, pages and next.config. It depends only on @decocms/blocks: never on @decocms/tanstack, never on an @decocms/apps-* package (exports.test.ts checks both).

What's in it

Import Contents
@decocms/nextjs/proxy decideDraft(cms, request, { site, previewHosts }), draftRequestHeaders (adds x-deco-draft, removes a forged copy), rewriteToDraftRoute (/_draft), applyDraft (cookie plus draftResponseHeaders()), isDraftRoutePath, draftProxy. No React, no next/headers, no block map.
@decocms/nextjs/server bindDraft(cms, { searchParams, site, previewHosts }): reads the param, then x-deco-draft, then the cookie, with the same host allowlist. It reads no header when previews are off, so a static page stays static. Also activeDraftPointer and contentClient(cms). The draft lives in React's cache().
@decocms/nextjs DraftPreviewIndicator (renders DraftBadge for the bound draft), DraftBadge, and StudioBridge: @decocms/blocks/preview's bridge with trustedOrigins set to the package's STUDIO_ORIGINS, so the layout still writes <StudioBridge site="my-store" />. Also the package's own draft names and Studio origins (below).
@decocms/nextjs/config withDeco(nextConfig, { draftHeaders, studioOrigins }): v7's two draft header rules go first, and STUDIO_ORIGINS goes into allowedDevOrigins. No rewrites and no image rules. Plain CommonJS shipped from src, so next.config.js can require() it.
@decocms/nextjs/image-loader createDecoImageLoader(imageUrl, { fallback }) and nextImageOptimizer. Platform-neutral: the site composes its platform's helpers into the ImageUrl (below).

Dev mode (PO decision 1, 2026-10-15). isNextDev is gone. createCMS reads NODE_ENV itself (#693), so a Next site passes only { content } and next dev keeps serving the local content; createCMS({ dev }) still overrides it. The binding smoke app and the README use the default. After the change the smoke app builds, type-checks and passes its matrix (21 checks on next start), and the 109 package and root tests/ tests pass.

Edit shortcut (PO decision 4). StudioBridge passes its props through, so Next sites get blocks' default: the "." shortcut is on unless the layout passes editShortcut={false}. The README says so.

Draft names and Studio's origins (PO review of #693). @decocms/blocks no longer exports them; each binding owns a copy. This package's is src/draft.ts (DRAFT_PARAM __draft, DRAFT_COOKIE __deco_draft, DRAFT_HEADER x-deco-draft, draftResponseHeaders) and src/studio.ts (STUDIO_ORIGINS, STUDIO_FRAME_ANCESTORS, isStudioOrigin), with the same values as @decocms/tanstack's and never imported from it. The proxy, drafts.ts and /server use it, config.test.ts holds withDeco's CommonJS copy equal to it, and the root exports it for a site's own code.

Draft hosts (D1). v7's readAllowedHosts / isDraftHostAllowed / isDraftPreviewEnabled logic is ported unchanged into this package (src/drafts.ts), with the same cases as @decocms/tanstack:

  • Allowed: the preview hosts the site declares (the CMS block's; none when it lists none, as in v7), plus <site>.deco.site and <site>.deco-cx.workers.dev. With no list and no site, previews are off and bindDraft never reads the request.
  • previewHosts: [...] replaces the block's list; previewHosts: "none" turns previews off everywhere.
  • The host checked is the visitor's: x-forwarded-host, else host.

Images (PO review of #694). The loader knows no commerce platform. A Next storefront's loaderFile composes the helpers itself:

createDecoImageLoader(createImageUrl({ providers: [
  vtexCatalogWebp(), vtexFileManager({ via: "query" }),           // @decocms/apps-vtex/image
  decoCdn({ quality: "high", fit: "contain", layout: "quality-last" }), // @decocms/blocks/image
] }), { fallback: nextImageOptimizer });

tests/nextjs-image-loader.golden.test.ts (in the root tests/, because the package depends on no apps-*) runs exactly that composition over the next/image golden URLs of @decocms/blocks and @decocms/apps-vtex: 1,212 cases (via: "thumbor" and via: "query"). The only changed cases are the 60 of the PO-approved fix 2 from #694: an already-resized Deco CDN URL in content is re-resized from its src, where it used to become src=image. The fixture marks each of them with before and reason, and the test asserts that nothing else changed (3af7b46). A mutation check (swapping via) makes it fail.

Approved changes (PO, 2026-10-14)

Tests

  • 80 package tests: the allowlist matrix; proxy decisions, rewrites and headers against real NextRequest/NextResponse; bindDraft order and gating; the badge; the bridge renders blocks' script with exactly Studio's four origins and passes editShortcut/nonce; the moved draft.test.ts/studio.test.ts; withDeco's names held equal to the package's; the loader's resize/fallback rules; the exports map and esbuild graphs (/proxy has no React or next/headers; /image-loader is pure); no @decocms/tanstack or @decocms/apps-* dependency or import.
  • examples/nextjs-binding-smoke (Next 16, next build + next start) runs a 23-point matrix against a local draft server, all passing: the draft content on the draft route, no-store and noindex, the cookie and how it ends, the allowlist on a Deco host vs. any other host, a forged header ignored, a direct /_draft hit gets a 404, the Studio bridge and the origins it answers (new), the image loader in srcset, and a proxy bundle with no block map and no React. The example's ImageUrl is now decoCdn({ fit: "contain" }), since blocks' default fit is cover. A CI job runs it.
  • After the fix-2 merge: the next/image golden test, the image-loader tests and every root tests/ file pass. Full gates for the stack are at the top (feat: the v7-to-v8 migrator and skill use @decocms/tanstack and @decocms/nextjs #700).
  • bun run check, bun run build, skills:check and skills:readme:check pass. bun run test: 2,361 passed, 2 failed: the known DS-2 in delivery.cli.test.ts, and a timeout in protocol/storage/fs/git.test.ts under full-suite load (that file passes 21/21 alone).

Validated locally on the two Next storefronts (before the PO review; not pushed)

For each site: I packed this branch, removed the vendored draft helpers, badge, mark and bridge, replaced the hand-written next.config draft rules with withDeco, built the loader on the image helpers, and added dev. Each built with next build --webpack under 2 GB, its jest suite passed, and a header matrix on next start passed (22/22). These local site branches were not repacked after the review: the site now imports vtexCatalogWebp/vtexFileManager from @decocms/apps-vtex/image, and the golden test above stands for the URL check, now byte-identical for both storefronts' loaders (the file-manager-to-Thumbor change for the store on via: "query" is now PO-approved, as a site change).

Lines (before review)
A storefront −924 / +115
Another storefront −887 / +165 (the proxy gets its own CMS handle with no block map)

For the PO

  • New example, not examples/nextjs-smoke. That example is the docs' Next.js guide, and guides.cli.test.ts nx-02 pins it to @decocms/blocks alone. The package's smoke app is examples/nextjs-binding-smoke, like tanstack-worker-smoke. The docs' Next.js page needs updating before nx-02 can change.
  • Peer next: ^16.0.0, as the plan says. Both storefronts are on 16. Next 15 isn't tested.
  • site adds the Deco hosts, as in v7 when the site name was known.
  • Next sets Vary itself on the draft route. Cache-Control: no-store, private and noindex do arrive; Vary: Cookie doesn't.
  • DecoImage is not shipped. A Server Component can't pass the ImageUrl function to a client wrapper, and both storefronts use loaderFile anyway.
  • A Next quirk: next start -H 127.0.0.1 makes Next treat a proxy rewrite as an external URL. The smoke app binds the default host. Production hosts aren't affected.
  • Release config and npm commands are in feat: release @decocms/tanstack and @decocms/nextjs in lockstep with blocks at 8.3.0 #699.

https://claude.ai/code/session_01WNwbSEePYNcY5YCgqZURig

StudioPage (2026-10-16, aa2e0431, ec218311)

  • @decocms/nextjs re-exports StudioPage. A CMS page renders <StudioPage pathTemplate={match.entry.path} />, so "." opens that page in Studio: the root layout stays across navigations and can't know it. It's a <meta> React puts in the head, so the page's markup doesn't change. The README shows where it goes.
  • StudioBridge passes the new page prop through like the others.

Main refresh (2026-10-17, 73b9b98d)

🤖 Generated with Claude Code

https://claude.ai/code/session_016ZsmzpZ2zahRBoATBb2tBu

@tlgimenes tlgimenes changed the title feat: @decocms/nextjs for v8: draft proxy and pages helpers, the v7 draft host allowlist, withDeco() and the image loader feat: @decocms/nextjs for v8: draft proxy and pages helpers, its own draft names and Studio origins, withDeco() and a platform-neutral image loader Oct 14, 2026
tlgimenes added a commit that referenced this pull request Oct 14, 2026
Brings in the PO review down the stack: blocks without the draft names or
Studio's origins (#693), the platform-neutral @decocms/blocks/image with the
@decocms/apps-vtex/image and @decocms/apps-shopify/image helper subpaths
(#694), StudioBridge's required trustedOrigins (#695), and each binding's own
copy of the draft names and Studio's origins (#696, #697).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WNwbSEePYNcY5YCgqZURig
@tlgimenes
tlgimenes marked this pull request as ready for review October 18, 2026 13:19
@tlgimenes
tlgimenes requested a review from vibe-dex as a code owner October 18, 2026 13:19
@tlgimenes
tlgimenes added this pull request to stack #721 October 18, 2026 18:51
tlgimenes added a commit that referenced this pull request Oct 18, 2026
… stops at the first match (#693)

## What this PR does

Three product-owner decisions (2026-10-14/15) in `@decocms/blocks`. The
rest of the stack (#694 and up) merges this branch.

### 1. `createCMS` reads `NODE_ENV` again to decide dev mode (d03448c)

- With no `dev` option, a `createCMS` with `site` stays on local files
when `process.env.NODE_ENV === "development"`. Hosted releases are never
swapped in, and drafts still load.
- The read is guarded (`typeof process !== "undefined" && process.env !=
null && …`), so a Worker or browser without `process` counts as
production. It is spelled `process.env.NODE_ENV` so a bundler's `define`
can replace it.
- The explicit `dev` option, which shipped in 8.0–8.2, stays as an
override in both directions (`dev: false` forces swaps even when
`NODE_ENV=development`).
- This is the SDK's only environment read. `noEnv.test.ts` allows
exactly that one line. `remoteLoader` itself still reads no environment.
- Conformance: four new H-5 tests (default, override, production or
unset, no `process`). Each was mutation-checked.
- Removing `isNextDev` from `@decocms/nextjs`, the migrator, the skill
and the smoke apps happens in #697 and #700, not here.

### 2. `deco schema --check` (fa83481)

- For CI: generates the schema in memory, writes nothing, and exits 1
when `.deco/schema.gen.json` is missing or differs from what `deco
schema` would write. The message says what moved:
  - blocks that are new in code or gone,
  - the number of changed definitions,
  - the generating version,
  - or formatting only.

  It ends with: Run `deco schema` and commit .deco/schema.gen.json.
- Schema errors exit 1 with the errors. `--check` and `--watch` can't be
combined, and there is no dev watch.
- Usage line: `deco schema [--root <dir>] [--watch | --check]`. Seven
tests in `cli/run.test.ts`, including one through the bin under plain
Node. `dd-06` follows the new usage line.
- The migrator adds it to each site's CI workflow in #700.

### 3. `multivariate` stops at the first matching rule, as v7 did
(ac23a70)

- Before this change, the resolver resolved every variant's rule before
the built-in `multivariate` ran. A matcher after the winner still ran,
so a random rule there drew a number and recorded a cohort.
- Now the built-in `multivariate` (marked the way `lazy` is) gets its
rules resolved in order, one at a time, up to the first `true` one.
Later variants are left out and their matchers are never called.
- A `multivariate` that the site declares in its block map replaces the
built-in and still gets every rule resolved, like any other block.
- Legacy multivariate types (`website/flags/multivariate.ts`, …) go
through the same path.
- `builtin-03/mv-02` now claims first-match order. That test changed
because the docs claim changes. New tests cover in-order evaluation, a
random rule after the winner never drawing, legacy types, and the
block-map override. Mutation-checked: 4 fail without the change.
- CLAUDE.md now says that `lazy` and the built-in `multivariate` are the
resolver's special cases.

### Docs site follow-up (deco-sites/docs-tanstack, `/next/*`)

- **api-reference / releases-and-drafts**: `dev` defaults to `NODE_ENV
=== "development"` (guarded; `false` without `process`). Pass `dev` to
override it, e.g. `dev: import.meta.env.DEV` on a Worker. Remove "the
SDK reads no environment variable" wherever it refers to `dev`.
- **cli / checking**: `deco schema --check` (usage line, exit codes, the
message) and a CI snippet that runs `deco schema --check`.
- **matchers-and-variants** line 75: replace "Rules aren't lazy: they're
cheap booleans and always run." with "Rules run in order and stop at the
first `true` one, as in v7: a later rule's matcher never runs, so a
random rule after the winner draws nothing and sets no cookie. A
`multivariate` you declare in your block map gets every rule."
- **how-resolution-works**: `lazy` is no longer the only special case.
Add the built-in `multivariate`'s in-order rules.

### Gates

- `bun run check` passes.
- `bun run build` passes.
- `skills:check` and `skills:readme:check` pass.
- A plain-Node import of every built export works (22), and so does
`deco --help`.
- `bun run test` (2 GB): 2092 pass, 3 fail, 95 skipped.
  - DS-2 is a known failure on `main` since #689.
- Two `schema.test.ts` tests hit the 5 s timeout under full-suite load.
They pass alone (116/116 with noEnv, guides.cli and telemetry).

## Draft shape and block JSON: unchanged (2026-10-16)

Two who-edited-what experiments came and went on this branch, and the
net change is none:

- A top-level `edits` field on the draft (`00125500`), reverted in
`a886d720`.
- A reserved `__meta` key on saved blocks that the resolver dropped
(`b1cd9a13`, `36fb75f1`), reverted in the commit on top. Both reverts
are merged up the stack.

PO: "only have metadata and changed by on v8 hosted". Studio keeps who
and when in the hosted draft object's storage metadata, so the draft
stays exactly `{ set, delete }` and blocks has no reserved metadata key.
The tree at M2 equals its state before these commits.

https://claude.ai/code/session_016ZsmzpZ2zahRBoATBb2tBu

### Main refresh (2026-10-17, `63b9e6d2`)
- Merged main `8bd3d88c` (#709) into this branch (normal merge, no
conflicts), then merged up the stack to M2 #707.
- Gates at the top of the stack (M2 `5131a3c1`): `bun run check`, `bun
run build`, `skills:check`, `skills:readme:check` pass. `bun run test`
(2 GB memory cap): 122 files pass, 1 skipped; 2,745 tests pass, 95
skipped, 0 fail. DS-2 now passes (fixed on main by #709); no timeouts
this run.
- CI on this PR's new head: all checks pass.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
tlgimenes added a commit that referenced this pull request Oct 18, 2026
…image providers in their packages (#694)

Stacked on #693 (P2 of the v8 framework-packages plan). Reworked after
the product owner's review: `@decocms/blocks` keeps framework code only,
and nothing that knows VTEX, Shopify or another commerce platform.

## What

**`@decocms/blocks/image`** (platform-neutral): pure functions, no
React, no module state.

- `decoCdn(options)`: the Deco image CDN
(`https://<domain>/image?fit=&width=…&src=`). Options: `domain`,
`quality` (tier), `fit` (default `cover`, as v7's `getSrcSet`/`Image`),
`legacyHosts` (default `["decoims.com"]` on the Cloudflare CDNs),
`sources` (`"deco"` default, `"all"` for v7's "everything else goes
through the CDN", or a predicate), `stripAssetHosts` (`"leading"`, the
default since the PO's 2026-10-15 decision: v7 from 7.71.4; or
`"anywhere"`: v7 up to 7.71.3 and two storefronts' vendored helpers),
`layout` (`"src-last"` or `"quality-last"`).
- `createImageUrl({ providers })`: one `ImageUrl` per site, with
`isOptimizable` and `hosts()`. Providers are tried in order; a
provider's `format` may return `null` to leave a source to the next one.
- `srcSet`, `parseSrcSet`, `preloadLink`, and the generic types
(`ImageProvider`, `ImageUrl`, `ResizeOptions`, `Quality`, `Fit`, …).
`srcSet` without a width writes v7's two `width=NaN … NaNw` candidates,
as v7's `getSrcSet` did for an `Image` or `Source` without a width (a
storefront's pages have 12 such `<source>` tags; before this, they lost
their srcset).

**`@decocms/apps-vtex/image`**: VTEX's URL formats as providers. They
are pure helpers over the blocks types: no fetch, no React, no env
reads, no runtime imports.

- `vtexCatalog()`: v7's `Image` rule. VTEX hosts, `{id}-{w}-{h ?? w}`,
URL re-serialised.
- `vtexCatalogFrame({ frame? })`: any host, a fixed frame or the call's
box, rounded.
- `vtexCatalogWebp({ quality? })`: the next/image loaders' rule.
`{id}-{w}-auto/{file}.webp?…&quality=` on VTEX's 1-10 scale.
- `vtexFileManager({ via: "query" | "thumbor", quality? })`.

**`@decocms/apps-shopify/image`**: `shopifyCdn()`, v7's rule (`width`,
`height` when given, `crop=center`).

A site lists the platform providers before `decoCdn`. The bindings never
depend on an `apps-*` package; sites wire the helper in. v7's
`registerImageCdnDomain`/`registerImageQuality` do not come back: they
were module state. Their values are `decoCdn`'s `domain` and `quality`.

## Golden URLs: only the approved changes

The fixtures were regenerated by running each v8 storefront's own
helpers, **unchanged**:

- the three vendored v7 `getOptimizedMediaUrl`/`getSrcSet` variants
- two next/image loaders
- a fixed-frame catalog loader

The corpus grew to cover edge cases: unencoded characters, an asset host
inside another URL, already-resized CDN URLs, uppercase hosts, odd id
suffixes, store-domain catalog URLs, and fractional widths. The fixtures
are split per package:

| Package | Cases | Sources |
|---|---|---|
| `@decocms/blocks` | 1,508 | Deco hosts, other hosts, paths, `data:`,
`""` |
| `@decocms/apps-vtex` | 2,625 | catalog + file manager, composed with
`decoCdn` |
| `@decocms/apps-shopify` | 144 | Shopify CDN, composed with `decoCdn` |

Every case reproduces today's URL byte for byte, except 192 approved
`@decocms/blocks` cases:

- 160 for approved change 2 below (the two already-resized CDN sources,
in every config);
- 32 for approved change 3 (the source
`https://images.example.com/https://assets.decocache.com/…`, on the two
configs that keep `decoCdn`'s default with `sources: "all"`).

Each of those carries `before` (today's URL) and `reason`. The test
asserts that no other case changed, and that each change-3 `before` is
exactly what `stripAssetHosts: "anywhere"` still writes. The `apps-vtex`
and `apps-shopify` fixtures have no changed case and still assert that
none carries a `before`. Where a helper throws today, the case is
recorded as `<throws>`, and the provider still throws (v7's VTEX rule on
a URL that only mentions a VTEX host in its query). The fixtures use no
site names. The generator stays out of the repo because it reads the
sites' paths.

## Approved changes (PO, 2026-10-14 and 2026-10-15)

The product owner approved 1 and 2 on 2026-10-14 ("the image fixes are
good") and 3 on 2026-10-15:

1. **File-manager images on the next/image loader that still uses VTEX's
`?width=&aspect=true` resizer.** That resizer has answered 500 for
raster files since 2026-10-07. That store switches to `vtexFileManager({
via: "thumbor" })`, which the other loader already uses. This is a site
change only; no package changes.
2. **An already-resized Deco CDN URL pasted into content**
(`https://assets.decocms.com/image?…`, or the `decoims.com`,
`deco-assets.edgedeco.com` and `deco-assets.decoazn.com` endpoints).
Today it becomes `src=image`, or the whole `/image` URL without its
query, and the CDN cannot serve either one. `decoCdn` now re-resizes it
from its `src` by default (c80dd33, narrowed in 6b7e700). That covers
an encoded `src`, a nested CDN URL, `http` and any host case. Resizing a
result again gives the same URL. It applies only to the URLs `decoCdn`
already resized (its `domain` and legacy hosts with the default
`sources: "deco"`; every endpoint with `sources: "all"` or a predicate
that takes it): a Deco CDN URL it passed through before, such as a
`deco-assets.edgedeco.com` one under `sources: "deco"`, still passes
through unchanged, because it was served fine. Other URLs are
unaffected, including a non-Deco `/image` path and an `/image` URL with
no `src`. A differential fuzz against the previous commit (9 configs, 10
hosts, 6 path shapes) finds 108 changed URLs, every one of them
`src=image` or `src=<cdn>/image` before.

3. **`stripAssetHosts` defaults to `"leading"`** (afe430c). An asset
host (`assets.decocache.com/`, the S3 bucket) is removed only where the
source starts with it, as v7's `Image` does since 7.71.4. Two
storefronts' vendored helpers (and v7 up to 7.71.3) removed it anywhere,
so a source that only contains an asset URL
(`https://other.host/https://assets.decocache.com/x.png`) used to lose
that part and now keeps it. Sources that start with an asset host, which
is every one the storefronts' content has in the corpus, give the same
URL either way. `"anywhere"` stays an option. Follow-up in the migrator
(#700): stop emitting `"anywhere"` and count and report the URLs this
changes per site.

## Proposals for the PO (not decided, not in the code)

4. **A mobile app's VTEX helper copies disagree with each other.** One
drops the source's query; the other leaves a pre-sized `-W-auto` id at
its baked size. The app does not use these packages, so it is out of the
golden suite. Proposal: point it at one helper.

Nuvemshop's image helper stays in the store's own code (PO, 2026-10-14).
There is no `apps-nuvemshop` package.

## Checks

Decision 3 (afe430c, on top of #693's decisions 1–3 merged in
d654d9a): `bun run check`, `bun run build`, `skills:check` and
`skills:readme:check` pass, and plain Node imports all 24 built exports
(`deco --help` runs). `bun run test` (2 GB): 2150 passed, 3 failed: DS-2
(fails on main too; fixed separately) and two `schema.test.ts` timeouts
under full-suite load (58/58 alone). Image tests 48/48 across the three
packages; reverting the default fails three of them.

Adversarial pass (6b7e700): c80dd33 had also widened `decoCdn`'s
default match to every Deco CDN endpoint, which changed 168 URLs that
used to pass through and were served fine; the match is back to the
pre-fix sources, and a new unit test pins those pass-throughs. `bun run
check` and `bun run build` pass; image tests 27/27; the golden fixtures
are unchanged (160 approved cases). Full gates at the top of the stack
(#700).

Fix 2 (c80dd33): `bun run check`, `bun run build`, `skills:check` and
`skills:readme:check` pass. `bun run test`: 2133 passed, 2 failed: DS-2
(the known flake) and a `schema.test.ts` timeout under full-suite load,
which passes 58/58 alone. The image tests pass 26/26, with 6 new fix-2
unit tests.

Review pass (2026-10-14): the `srcSet` fix above (ea0a6bf). Its golden
markup cases (v7's own components, no width) are in #700's
`tests/tanstack-image-markup.golden.test.ts`. Full gates at the top of
the stack (#700).


First round (before the PO review):

- `bun run check` passes. `bun run build` passes and emits
`dist/v8/image.*`, `apps-vtex/dist/image.*` and
`apps-shopify/dist/image.*`. Plain Node imports the built
`@decocms/apps-vtex/image`.
- `bun run test`: 2124 passed, 4 failed:
  - DS-2 in `delivery.cli.test.ts`, the known flake.
- Three CLI conformance timeouts under full-suite load (`cli-02`,
`qs-01/in-03`, `saved-03/saved-11`). Run alone, those files pass
179/179.
- `bun run skills:check` and `bun run skills:readme:check` pass.
- Bundle tests:
- `@decocms/blocks/image` bundles for a browser and for workerd with no
Node built-ins and no React (esbuild).
- New `tests/upstream-helpers.guardrail.test.ts`: every `apps-*` helper
subpath gets the same bundle check, plus a purity check (no network,
React, env reads or runtime imports). Its comment records that the PO
asked for helper subpaths in `apps-*`.
- `CLAUDE.md` now says where platform helpers live.

**For the PRs above (#696, #697, #700):** the API changed:

- `vtexCatalog`/`vtexFileManager`/`shopify` are no longer in
`@decocms/blocks/image`.
- `parse`/`ParsedImage` and `proxyOtherHosts` are gone (use `sources:
"all"`).
- `@decocms/tanstack`'s default `ImageUrl` cannot include VTEX/Shopify,
because it must not depend on `apps-*`.

### Main refresh (2026-10-17, `0103f85f`)
- Merged P1 `63b9e6d2` into this branch (normal merge, no conflicts),
then merged up the stack to M2 #707.
- Gates at the top of the stack (M2 `5131a3c1`): `bun run check`, `bun
run build`, `skills:check`, `skills:readme:check` pass. `bun run test`
(2 GB memory cap): 122 files pass, 1 skipped; 2,745 tests pass, 95
skipped, 0 fail. DS-2 now passes (fixed on main by #709); no timeouts
this run.
- CI on this PR's new head: all checks pass.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_016ZsmzpZ2zahRBoATBb2tBu

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…draft names and Studio origins, withDeco() and a platform-neutral image loader (#697)

Rebased onto main as one commit per PR (PO, 2026-10-18); the previous history is kept on backup/nextjs-v8-2026-10-18.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016ZsmzpZ2zahRBoATBb2tBu
@tlgimenes

Copy link
Copy Markdown
Contributor Author

Superseded by #722 so the stack lands as one commit and one 8.4.0 release (PO, 2026-10-18).

tlgimenes added a commit that referenced this pull request Oct 18, 2026
…cocms/compat-v7, /preview, lockstep release and the migrator (#722)

This PR replaces the 11 stacked PRs #695 … #707 so the rest of the v8
framework packages land on `main` as **one commit and one release,
8.4.0**, publishing all 11 packages together: `@decocms/blocks`,
`@decocms/tanstack`, `@decocms/nextjs`, `@decocms/compat-v7` and the
seven `@decocms/apps-*`. Its branch is #707's
(`feat/migrator-invoke-scaffold`), already rebased onto `main` with one
commit per former PR and their trees unchanged, plus one commit that
raises every `@decocms/blocks` peer floor to `^8.4.0`.

#693 and #694 are already on `main` and shipped in 8.3.0 (`NODE_ENV` dev
default, `deco schema --check`, first-match multivariate, the
platform-neutral `/image` with `@decocms/apps-vtex/image` and
`@decocms/apps-shopify/image`).

## What lands

### #695 — `@decocms/blocks/preview`: the draft badge and the Studio
bridge
- `DraftBadge({ pointer, exitHref? })`: v7's "Preview mode" pill,
unchanged on screen. Renders nothing without a pointer, on the server
and inside a frame. The inlined Deco mark is now a 36px PNG (~2KB, v7
inlined ~22KB).
- `StudioBridge({ site, trustedOrigins, editShortcut?, nonce? })`: v7's
`LiveControls` as one static inline script, so it runs before hydration
and a Server Component can render it. `trustedOrigins` is required; it
answers only the parent frame from those origins.
- `@decocms/blocks` exports no Studio origins and no draft names: the
bindings own them.
- PO decision 4: the "." / Ctrl+Shift+E edit shortcut is on by default,
as in v7; `editShortcut={false}` turns it off.

### #696 — `@decocms/tanstack` for v8
- For TanStack Start on Cloudflare Workers, depending only on
`@decocms/blocks`. Subpaths: root (draft names, `draftResponseHeaders`,
`STUDIO_ORIGINS`), `/worker` (`createDecoWorker`), `/server`, `/start`,
`/router`, `/react` (`DecoDocument`, `NavigationProgress`,
`StableOutlet`), `/vite` (`decoTanstack`), `/scope`.
- `createDecoWorker`: Studio framing, v7's draft host allowlist (D1),
CMS redirects, the edge cache (build + revision + device + segment key,
SWR/SIE, never storing private, signed-in or degraded responses), the
`__cseg` server-function cache check, Set-Cookie dedup, immutable
assets. `onCache` is the only metrics hook (D3); build hash from CI's
sha (D4).
- Owns the draft names, headers and Studio origins that #693 had put in
blocks (PO review of #693); values unchanged.

### #697 — `@decocms/nextjs` for v8
- Helpers for any Next.js App Router app, no hosting assumptions,
depending only on `@decocms/blocks`: `/proxy` (`decideDraft`,
`draftProxy`, …), `/server` (`bindDraft`, `contentClient`), root
(`DraftPreviewIndicator`, `DraftBadge`, `StudioBridge` with Studio's
origins), `/config` (`withDeco`), `/image-loader`
(`createDecoImageLoader`, platform-neutral).
- PO decision 1: `isNextDev` is gone; `createCMS` reads `NODE_ENV`. PO
decision 4: the edit shortcut is on by default. Its own copy of the
draft names and Studio origins (PO review of #693). Image golden test:
1,212 cases, only the 60 of PO-approved fix 2 (#694) change.

### #699 — lockstep release
- `.releaserc.json` publishes every package in `packages/` at one
version on `latest` from `main`, blocks first, then the bindings.
- Every package that builds on blocks takes it as a caret **peer** (now
`^8.4.0`) with `workspace:*` only in `devDependencies`, so a site
installs one blocks copy.
- `scripts/sync-versions.mjs` writes the version and refuses a plain
in-repo dependency or a peer floor above the release.
`tests/release.test.ts` checks the allowlist, the ranges, every export's
shape and what each tarball ships; CI runs it on the built dist.

### #700 — the migrator and skill use the bindings
- The v7-to-v8 script and the `deco-v7-to-v8-migration` skill move sites
onto `@decocms/tanstack` / `@decocms/nextjs` instead of copying v7's
worker, draft, bridge and image code.
- `@decocms/tanstack/react` gets v7's `Image`, `Picture`, `Source` (same
props and markup, URLs from `ImageUrlProvider`); 160 golden markup
cases, zero changed.
- PO decisions 1, 2 and 5: no dev flag; the script adds `deco schema
--check` to the site's CI; `decoCdn` strips only a leading asset host
and the report lists every URL that changes.

### #702 — `@decocms/compat-v7`: types, device, scripts, clx
- The PO-approved home (2026-10-14) for v7's **pure** helpers on v8, so
migrated sites stop keeping copies. No v7 runtime (`ctx`, invoke,
request scope), no env reads, nothing added to blocks.
- `/types` (`SectionProps` = the loader's awaited return, per the PO),
`/device`, `/script`, `/clx`. v7's own files are hash-pinned fixtures
and every helper is compared against them over seeded inputs.

### #703 — `@decocms/compat-v7/matchers`
- v7's website matchers with v7's results; each takes the request as its
second argument. `random` is latest 7.x's sticky random on the
`deco_segment` cookie (PO decision), keyed by the saved block's name
(`cohort`).

### #704 — `@decocms/compat-v7/sections`
- `runSectionLoaders` / `runSectionLoader`: v7's `(props, req)` section
loaders after a page resolves, with v7's nested walk (deep, or `nested:
"direct"` for 7.77.12 and earlier), `__pageUrl`/`__pagePath`, and the
`degraded` list. v7's mixins. Reading `ctx` throws with what to use
instead.

### #705 — `@decocms/compat-v7` `/commerce`, `/tanstack`, `/nextjs`
- `/commerce/*`: v7's `@decocms/apps-commerce` pure files under the same
layout (AST-equal to v7, 5,000 generated inputs each).
- `/tanstack` and `/nextjs`: `matcherContext`, `commitSegmentCookie`,
`cohortSegment`, `requestDevice`, `DeviceProvider`.
- `/tanstack/worker` (PO decision 6): v7's `withABTesting` legacy-origin
split as a `createDecoWorker` `routes` handler, matched to v7 over 3,000
seeded requests. PO decision 3 checked against the compat random.

### #706 — the migrator imports `@decocms/compat-v7`
- Rewrites v7 helper and `@decocms/apps-commerce` imports onto
compat-v7, rewrites `ctx.device`, turns `registerSectionLoaders` into
`sectionLoaders` and wires `loadSections`, registers the matchers the
content uses and writes the image URLs module.
- PO decision 8: every section's own `loader` runs, and each one v7
never ran is reported. PO decision 9: blocks are registered under their
v7 names only.

### #707 — the migrator writes invoke, app clients, the page setup and
stubs
- Each `/deco/invoke` key becomes one server function (TanStack Start
`GET` loaders marked private and `POST` actions; Next.js `"use
server"`), imported at each call site.
- PO decision 7: VTEX invoke-map keys need an explicit `--vtex-invoke
keep|v8` choice, no default.
- `deco-vtex`/`-shopify`/`-wake`/`-resend` app blocks become
`src/clients/<app>.ts`; `src/migration-stubs.ts` holds deprecated stubs
for v7 runtime with no port; the page setup (`src/cms.ts`, `open-page`,
the catch-all route) is written per binding.

### This PR's own commit — peer floors `^8.4.0`
The bindings and compat-v7 use blocks APIs that 8.3.0 doesn't have
(`@decocms/blocks/preview` and the rest of this stack), so every
`@decocms/blocks` peer (and compat-v7's optional binding peers) is
`^8.4.0`. `tests/release.test.ts` syncs at 8.4.0 and 8.5.1 and refuses
8.3.x; the migrator writes `^8.4.0`; CLAUDE.md, the README and the skill
name 8.4 as the floor.

## Checks

- **Release dry run** in a throwaway clone of a mirror with the tags
(deleted afterwards; nothing pushed to GitHub or published): `main` +
this branch squashed into one commit with this PR's title.
`semantic-release --dry-run`: "Found git tag blocks-v8.3.0 … The next
release version is 8.4.0". The prepare step (`VERSION=8.4.0 node
scripts/sync-versions.mjs && bun run build`): 11 manifests at 8.4.0,
every peer `^8.4.0`, all builds exit 0. `npm publish --dry-run --tag
latest` for all 11: `@decocms/blocks@8.4.0` …
`@decocms/apps-wake@8.4.0`, each "with tag latest". The 11 tarballs
installed together: `npm ls @decocms/blocks` shows one `8.4.0`, every
other entry deduped; no required peer is unmet.
- **Gates at the top:** `bun run check`, `bun run build`,
`skills:check`, `skills:readme:check`, `bun test tests/release.test.ts`
(42 pass), the compat-v7 tests (13 files, 153 pass), and `bun run test`
under a 2 GB cap: 122 files pass, 1 skipped; 2,746 tests pass, 95
skipped, 0 fail.

## Landing

1. Approve, then **squash** with this PR's `feat:` title. The squash
message is the PR body (repo setting), so this body is what
commit-analyzer reads: one `feat:`, a minor release.
2. The release publishes **8.4.0 on `latest`** for all 11 packages.
3. **Before landing**, check that npm Trusted Publishing for
`@decocms/tanstack`, `@decocms/nextjs` and `@decocms/compat-v7` accepts
`main`'s `.github/workflows/release.yml`. The bindings were last
published from the 7.x branch: npm's trusted publisher names the repo
and workflow file, not a branch, so `main` should be accepted, but if
either is tied to a GitHub environment, add it for `main` first.
compat-v7's trust config already exists and its `0.0.0` placeholder is
published.

Once this lands, the 11 stacked PRs can be closed.

## npm commands for the PO after the release (not run)

```bash
# 1. Remove the stale `next` dist-tag (8.1.0) from blocks and every apps-* that has it (all seven do today).
npm dist-tag rm @decocms/blocks next
npm dist-tag rm @decocms/apps-algolia next
npm dist-tag rm @decocms/apps-magento next
npm dist-tag rm @decocms/apps-resend next
npm dist-tag rm @decocms/apps-sfmc-personalization next
npm dist-tag rm @decocms/apps-shopify next
npm dist-tag rm @decocms/apps-vtex next
npm dist-tag rm @decocms/apps-wake next

# 2. Rewrite the 8.0.0 deprecation (it says "use @latest (7.x)", wrong once latest is 8.4.0).
npm deprecate @decocms/tanstack@8.0.0 "Published by mistake. Use ^8.4.0 for v8, or 7.x for v7."
npm deprecate @decocms/nextjs@8.0.0 "Published by mistake. Use ^8.4.0 for v8, or 7.x for v7."

# 3. Deprecate the two prereleases (not deprecated today).
npm deprecate @decocms/tanstack@"8.0.0-next.0 || 8.1.0-next.0" "Prerelease. Use ^8.4.0 for v8, or 7.x for v7."
npm deprecate @decocms/nextjs@"8.0.0-next.0 || 8.1.0-next.0" "Prerelease. Use ^8.4.0 for v8, or 7.x for v7."
```

No `latest-7` command is needed: #698 already moved `latest-7` to 7.80.2
for both bindings. `latest` moves to 8.4.0 by itself when the release
publishes.

Checks afterwards:

```bash
npm view @decocms/blocks dist-tags      # { latest: '8.4.0', 'latest-7': '7.80.2' }, no next
npm view @decocms/tanstack dist-tags    # { latest: '8.4.0', 'latest-7': '7.80.2' }
npm view @decocms/nextjs dist-tags      # { latest: '8.4.0', 'latest-7': '7.80.2' }
npm view @decocms/compat-v7 dist-tags   # { latest: '8.4.0' }
for p in algolia magento resend sfmc-personalization shopify vtex wake; do npm view @decocms/apps-$p dist-tags; done   # latest: '8.4.0', no next
npm view @decocms/tanstack@8.0.0 deprecated
npm view @decocms/nextjs@8.1.0-next.0 deprecated
npm view @decocms/tanstack@8.4.0 peerDependencies   # @decocms/blocks: '^8.4.0'
```

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_016ZsmzpZ2zahRBoATBb2tBu


<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Replaces PRs #695–#707 so the v8 framework packages land as one commit
and one release: 8.4.0 publishes all 11 packages together
(`@decocms/blocks`, `@decocms/tanstack`, `@decocms/nextjs`,
`@decocms/compat-v7`, and the seven `@decocms/apps-*`). The v7-to-v8
migrator and its skill now move sites onto these bindings instead of
copying v7's worker, draft, bridge, and image code into the site.

**What ships**
- `@decocms/blocks/preview`: the draft badge and Studio bridge, as one
static inline script that runs before hydration.
- `@decocms/tanstack`: the TanStack Start binding on Cloudflare Workers
— drafts, edge cache, CMS redirects, draft names and Studio origins.
- `@decocms/nextjs`: the Next.js App Router binding — draft proxy,
content client, image loader, Studio bridge, without hosting
assumptions.
- `@decocms/compat-v7`: v7's pure helpers (types, device, scripts, clx,
matchers, section loaders, commerce files) with v7's output, so migrated
sites stop keeping their own copies.
- The migrator rewrites `/deco/invoke` calls into server functions,
writes the page setup per binding, registers v7 matchers and section
loaders, and reports everything left for a person.

**Release and migration**
- All packages release in lockstep at one version on `latest`; every
package that builds on blocks takes it as a `^8.4.0` caret peer, so a
site installs one blocks copy.
- Existing v7 sites stay on `latest-7`; `next` dist-tags and misplaced
`8.0.0`/prerelease deprecations must be cleaned up after release
(commands in the PR body).

<sup>Written for commit 6195fe5.
Summary will update on new commits.</sup>

<a href="https://cubic.dev/pr/decocms/blocks/pull/722?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="View guided diff"
src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a>
<a
href="https://www.cubic.dev/action/auto-fix/pr/decocms/blocks/722?returnTo=https%3A%2F%2Fgithub.com%2Fdecocms%2Fblocks%2Fpull%2F722&source=description"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img
alt="Turn on auto-fix"
src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@tlgimenes

Copy link
Copy Markdown
Contributor Author

Landed in #722 (squashed as one commit and one 8.4.0 release).

@tlgimenes tlgimenes closed this Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant