From 91ce9e533b0600b19a0ddf6ecd5f4e9546eed034 Mon Sep 17 00:00:00 2001 From: Rahul Varghese Date: Thu, 15 Oct 2026 07:31:59 +0530 Subject: [PATCH] CM3: ready to instantiate The as-built status names the PRs, every departure from upstream (experimental.useCache in place of experimental.ppr + useCache because cacheComponents hangs on the adapter; stable cacheLife/cacheTag imports; baseUrl on SITE_URL; the next/og font through ASSETS; moduleResolution bundler; React 19.2; an ESLint config and upstream's failing prettier check left unwired), the pinned versions with their reasons, what was verified locally and in Checks and what was not (the R2 apply, a live deploy, a real Shopify store). epic.yaml moves to completed. Orun-Task: CM-4 Co-Authored-By: Claude Fable 5.1 --- specs/epics/README.md | 2 +- specs/epics/commerce/IMPLEMENTATION-STATUS.md | 111 +++++++++++++++++- specs/epics/commerce/README.md | 4 +- specs/epics/commerce/epic.yaml | 2 +- specs/epics/commerce/implementation-plan.md | 8 +- 5 files changed, 113 insertions(+), 14 deletions(-) diff --git a/specs/epics/README.md b/specs/epics/README.md index cd4a3ae..ff72ff0 100644 --- a/specs/epics/README.md +++ b/specs/epics/README.md @@ -7,6 +7,6 @@ folder is the adoption; the merge creates the epic in the workspace. | Epic | Cluster | Status | What it is | |------|---------|--------|------------| -| [`commerce/`](./commerce/) | **CM** | Draft | Vercel's Next.js Commerce, equivalent in code and function, on Cloudflare Workers with the Shopify Storefront API as its backend | +| [`commerce/`](./commerce/) | **CM** | โœ… Shipped | Vercel's Next.js Commerce, equivalent in code and function, on Cloudflare Workers with the Shopify Storefront API as its backend | As-built โ‰  intent: what shipped lives in each epic's `IMPLEMENTATION-STATUS.md`. diff --git a/specs/epics/commerce/IMPLEMENTATION-STATUS.md b/specs/epics/commerce/IMPLEMENTATION-STATUS.md index 91103c7..0d8ac28 100644 --- a/specs/epics/commerce/IMPLEMENTATION-STATUS.md +++ b/specs/epics/commerce/IMPLEMENTATION-STATUS.md @@ -5,15 +5,114 @@ the code departed from `design.md` or from the upstream template. | Milestone | State | PR | |---|---|---| -| CM0 โ€” the spec | ๐Ÿ”„ In review | โ€” | -| CM1 โ€” the storefront on Workers | โฌœ Not started | โ€” | -| CM2 โ€” the cache infrastructure from Terraform | โฌœ Not started | โ€” | -| CM3 โ€” ready to instantiate | โฌœ Not started | โ€” | +| CM0 โ€” the spec | โœ… Shipped | [#1](https://github.com/sourceplane/commerce/pull/1) | +| CM1 โ€” the storefront on Workers | โœ… Shipped | [#2](https://github.com/sourceplane/commerce/pull/2) | +| CM2 โ€” the cache infrastructure from Terraform | โœ… Shipped (validated; apply gated on a linked workspace) | [#3](https://github.com/sourceplane/commerce/pull/3) | +| CM3 โ€” ready to instantiate | โœ… Shipped | [#4](https://github.com/sourceplane/commerce/pull/4) | ## Departures from the upstream template -Recorded as they land (CM1), consolidated in CM3. +Upstream is [vercel/commerce](https://github.com/vercel/commerce) at +`3761e52` (2026-06-10). `app/`, `components/` and `lib/` are byte-identical +to it except for the four files named below. + +### `next.config.ts`: `experimental.useCache`, not `experimental.ppr` + `useCache` + +Upstream enables `experimental.ppr`, `useCache` and `inlineCss` on a Next +15.6 canary. Next 16.3.8 (the adapter's floor) hard-deprecates +`experimental.ppr` into `cacheComponents`, and a Worker built with +`cacheComponents: true` hangs on every request under `@opennextjs/cloudflare` +1.20.11 (Cache Components' staged render ends each stage on workerd's +microtask `process.nextTick`; opennextjs-cloudflare#1450, fix PR #1318 +unmerged). `experimental.useCache: true` (deprecated in 16, a warning) +enables the same `"use cache"` / `"use cache: private"` / `cacheTag` / +`cacheLife` / `revalidateTag` / `updateTag` surface through OpenNext's +composable cache; `inlineCss` is kept. Partial prerendering is off: every +storefront route is dynamic. Upstream's root layout starts the cart's +private-cache promise outside any Suspense boundary, so no route had a +static shell there either. The port first tried `cacheComponents` โ€” it +built, after a sitemap `connection()`, a cached footer year and +`instant = false`, and then hung โ€” and reverted those three files to +upstream verbatim. + +### `lib/shopify/index.ts`: stable `cacheLife` / `cacheTag` imports + +`unstable_cacheLife as cacheLife, unstable_cacheTag as cacheTag` โ†’ +`cacheLife, cacheTag`. Next 16 logs an error on every call through the +`unstable_` names and will remove them. + +### `lib/utils.ts`: `baseUrl` honours `SITE_URL` + +`metadataBase`, robots and the sitemap are built on `baseUrl`, which +upstream derives from Vercel's `VERCEL_PROJECT_PRODUCTION_URL`. On +Cloudflare that is the `SITE_URL` wrangler var; the Vercel variable and the +`http://localhost:3000` default are kept behind it. + +### `components/opengraph-image.tsx`: the font through `ASSETS` + +Upstream reads `fonts/Inter-Bold.ttf` with `fs` from `process.cwd()`. A +Worker has no filesystem (`/bundle/fonts/โ€ฆ` does not exist). The font moved +to `public/fonts/Inter-Bold.ttf`; `loadFont()` reads it from disk first +(`next dev`, `next build`, Vercel) and, when that fails, through the +`ASSETS` binding via `getCloudflareContext({ async: true })`. +`cloudflare-env.d.ts` declares the binding's type (what `wrangler types` +would generate). `/opengraph-image` answers a 1200ร—630 PNG from the Worker. + +### `tsconfig.json`: `moduleResolution: bundler` + +Upstream's `node` resolution cannot see `@opennextjs/cloudflare`'s subpath +exports (`/config`, `/overrides/*`), which `open-next.config.ts` imports. + +### Around the template + +- `react` / `react-dom` ^19.2.1 (upstream 19.0.0): Next 16's peer range. +- An ESLint flat config over the workspace's shared config (upstream ships + none), with `caughtErrors: "none"` for the template's `catch (e)` server + actions. Lint is warnings-only (`console.log` guards, `any` in actions). +- Upstream's `test` script is `prettier --check`, which upstream's own HEAD + fails on two files (prettier 3 trailing commas in + `components/cart/actions.ts` and `lib/shopify/index.ts`). Both are kept + byte-identical; the `prettier` / `prettier:check` scripts remain but the + workspace `test` is `tests/web`. +- `.env.example` gains `SITE_URL` and a note on where each value lives; + `.dev.vars.example` lists the three Worker secrets. +- `tooling/migrations` (a `packages/db` checksum checker the skeleton + carries for Supabase ports) is not in this repository: no database. + +### Versions + +| Package | Version | Why | +|---|---|---| +| next | 16.3.8 | newest inside `@opennextjs/cloudflare` 1.20.11's peer range; 16.4 fails at Worker boot | +| @opennextjs/cloudflare | ^1.20.11 | R2 incremental cache, DO queue, DO sharded tag cache; `next/og` on the Worker | +| wrangler | ^4.151.0 | compatibility_date 2026-10-01; SQLite Durable Object migrations | +| react, react-dom | ^19.2.1 | Next 16 peer range (upstream 19.0.0) | +| typescript, tailwindcss, @tailwindcss/postcss, prettier | upstream's pins | unchanged | ## Verified -Recorded in CM3. +- Local: `pnpm run wire:fixture`, `pnpm typecheck`, `pnpm lint` (warnings + only), `pnpm test` (22 tests), `pnpm build` green on Node 25; + `terraform validate` green on `infra/terraform/cloudflare-r2`. +- `wrangler dev` over `.open-next/worker.js` with the fixture config, an + empty local bucket, local Durable Objects and no store: `/` 200 (the + un-configured storefront, "Next.js Commerce"), `/search` and + `/search?q=โ€ฆ` 200, `/product/` 404, `/robots.txt` 200, + `/opengraph-image` 200 (PNG 1200ร—630), `/favicon.ico` and the CSS chunk + 200, `/sitemap.xml` and `/` 500 (upstream's unguarded + `validateEnvironmentVariables` / `getPage`); `"use cache"` entries appear + in the bucket (`incremental-cache//*.composable`) after the first + request; `DOQueueHandler` and `DOShardedTagCache` namespaces exist. +- `POST /api/revalidate`: without a secret or with a wrong one, body + `{"status":401}` with HTTP 200 (upstream's Shopify-retry rule). With dummy + secrets in `.dev.vars` (a non-resolving `.invalid` store domain, never + committed): `products/update` and `collections/create` โ†’ + `{"status":200,"revalidated":true}` with Durable Object storage writes and + R2 puts observed; `orders/create` โ†’ `{"status":200}`; + `/product/` 500 (the unreachable store, as upstream). +- CI: `Checks` green on #2 and #3 (install, wire, typecheck, lint, test, + build on Node 22). +- Not verified: an apply of the R2 root, a live deploy, and the storefront + against a real Shopify store (no store was contacted) โ€” all need the + product linked to an Orun workspace with a Cloudflare connection + (`ORUN_CI` variable) and the three Worker secrets set (README). diff --git a/specs/epics/commerce/README.md b/specs/epics/commerce/README.md index 83738c4..548982b 100644 --- a/specs/epics/commerce/README.md +++ b/specs/epics/commerce/README.md @@ -8,7 +8,7 @@ The upstream code stays the code: `lib/shopify` (queries, mutations, reshaping, | Field | Value | |-------|-------| -| Status | Draft โ€” CM0 in review | +| Status | โœ… Shipped โ€” CM0โ€“CM3 landed (#1โ€“#4); R2 apply and live deploy gated on a linked workspace | | Cluster | **CM** (CM0โ€“CM3) | | Owner(s) | `apps/web` (the storefront) ยท `tests/web` (client + webhook tests) ยท `infra/terraform/cloudflare-r2` (the cache bucket) | | Builds on | `cirrus-baseline` conventions โ€” intent, components, the Checks lane, the gated Orun lane; the factory's `cloudflare-r2` root and `tooling/wire` renderer | @@ -16,7 +16,7 @@ The upstream code stays the code: `lib/shopify` (queries, mutations, reshaping, | Changes | Adds the Workers build, the cache bindings, the monorepo wrapper, tests, the R2 root and the deploy contract; the storefront's code is untouched except where Next 16 or Workers force a change (status file) | | Decisions locked | (1) OpenNext on Workers + Static Assets. (2) Incremental cache in R2, tag cache and queue in Durable Objects โ€” no D1, no KV. (3) `wrangler.jsonc` is rendered per environment from the R2 root's wiring document; never committed. (4) The Shopify facts are Worker secrets set once per environment; the deploy lane does not set them. (5) `experimental.useCache`, not `cacheComponents`, until the adapter runs staged renders. | | Gate | CM1 is the first user-visible rung. CM2 needs a workspace with a Cloudflare connection to apply; it is verified by `terraform validate` and `plan`. | -| Shipped as | โ€” | +| Shipped as | `main` after [#4](https://github.com/sourceplane/commerce/pull/4); verified locally under `wrangler dev` with the fixture config, an empty local bucket, local Durable Objects and dummy secrets | ## Read order diff --git a/specs/epics/commerce/epic.yaml b/specs/epics/commerce/epic.yaml index 8dcecf7..951bd8c 100644 --- a/specs/epics/commerce/epic.yaml +++ b/specs/epics/commerce/epic.yaml @@ -9,7 +9,7 @@ metadata: spec: title: "Vercel's Next.js Commerce on Cloudflare Workers" summary: "Vercel's Next.js Commerce โ€” the Shopify headless storefront: server components over the Storefront API, server-action cart, `\"use cache\"` data with tag revalidation from Shopify webhooks โ€” runs on Cloudflare Workers + Static Assets through @opennextjs/cloudflare, with the Next.js data cache in an R2 bucket provisioned by Terraform through Orun and the tag cache and revalidation queue in Durable Objects the Worker itself exports. The Shopify Storefront API stays the backend, reached with Worker secrets; nothing in the storefront's code changes beyond what Workers and Next 16 force." - state: draft + state: completed milestones: - name: "CM0 โ€” the spec" exitCriteria: diff --git a/specs/epics/commerce/implementation-plan.md b/specs/epics/commerce/implementation-plan.md index ec7f47e..a5045a7 100644 --- a/specs/epics/commerce/implementation-plan.md +++ b/specs/epics/commerce/implementation-plan.md @@ -3,7 +3,7 @@ Milestones land in order; each task is one pull request on an `orun/CM-n-` branch with an `Orun-Task: CM-n` trailer. -## CM0 โ€” the spec +## CM0 โ€” the spec โœ… This doc set, `epic.yaml` and the task contracts, merged to `main`. @@ -11,7 +11,7 @@ This doc set, `epic.yaml` and the task contracts, merged to `main`. - the five documents and `epic.yaml` are on `main` - `tasks/CM-1..CM-4.TaskContract.yaml` exist -## CM1 โ€” the storefront on Workers +## CM1 โ€” the storefront on Workers โœ… `apps/web` is the upstream template with the Workers build around it: `open-next.config.ts` names the R2 incremental cache, the Durable Object @@ -27,7 +27,7 @@ and the revalidation webhook without a network. - `POST /api/revalidate` answers `{"status":401}` without the secret and `{"status":200,"revalidated":true}` for a product or collection webhook with it, writing the tag to the Durable Object tag cache - `"use cache"` results land in the (local) R2 bucket at request time -## CM2 โ€” the cache infrastructure from Terraform +## CM2 โ€” the cache infrastructure from Terraform โœ… `infra/terraform/cloudflare-r2` provisions one bucket per environment and publishes its name as the `WIRING_CLOUDFLARE_R2` secret; `apps/web/component.yaml` @@ -40,7 +40,7 @@ the migration in the wrangler config creates them on the first deploy. - the component's `secretEnv` keys match the root's `secretOutputs` - the fixture's wiring keys match the template's tokens (`wire:fixture` renders) -## CM3 โ€” ready to instantiate +## CM3 โ€” ready to instantiate โœ… README (run, test, preview, deploy; the Shopify connection: Storefront token, store domain, webhook secret as Worker secrets, the menus and