Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion specs/epics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
111 changes: 105 additions & 6 deletions specs/epics/commerce/IMPLEMENTATION-STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<unknown>` 404, `/robots.txt` 200,
`/opengraph-image` 200 (PNG 1200×630), `/favicon.ico` and the CSS chunk
200, `/sitemap.xml` and `/<page>` 500 (upstream's unguarded
`validateEnvironmentVariables` / `getPage`); `"use cache"` entries appear
in the bucket (`incremental-cache/<buildId>/*.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/<handle>` 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).
4 changes: 2 additions & 2 deletions specs/epics/commerce/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ 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 |
| Upstream | [vercel/commerce](https://github.com/vercel/commerce) at `3761e52` (2026-06-10, "Use the Shopify integration in this template") |
| 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

Expand Down
2 changes: 1 addition & 1 deletion specs/epics/commerce/epic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions specs/epics/commerce/implementation-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
Milestones land in order; each task is one pull request on an
`orun/CM-n-<slug>` 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`.

**Done when**
- 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
Expand All @@ -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`
Expand All @@ -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
Expand Down
Loading