Skip to content

templates/react-router: add standalone RR7 storefront template#3818

Merged
mdamjanic7 merged 3 commits into
previewfrom
react-router-rr8-template
Jun 26, 2026
Merged

templates/react-router: add standalone RR7 storefront template#3818
mdamjanic7 merged 3 commits into
previewfrom
react-router-rr8-template

Conversation

@mdamjanic7

@mdamjanic7 mdamjanic7 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

One-off manual import of the generated standalone React Router 8 storefront template from the storefront-kit generator, added under a new top-level templates/ dir. Nothing under examples/ is changed.

What's here: the full five-page storefront (home, product, collection, collections index, search) with the real cart path, shared chrome, and analytics/consent layer.

Standalone by design — meant to be copy-pasted into a fresh repo by the build pipeline, so it runs on its own:

  • ships its own pnpm-lock.yaml, .npmrc, and LICENSE
  • pins @shopify/hydrogen to the published preview tag (not workspace:*)

Not a workspace member (templates/ is outside the pnpm-workspace globs), so install / build / typecheck / test / lint ignore it. The one supporting change is adding templates/** to the oxfmt ignore list (mirroring the source repo) so format:check doesn't reformat generated output.

Future imports will be automated; this is a one-off to test the flow.

@mdamjanic7 mdamjanic7 requested a review from a team as a code owner June 25, 2026 03:49
Adds the generated standalone React Router 8 five-page storefront (home,
product, collection, collections index, search) with the full cart path, shared
chrome, and analytics/consent layer, under a new top-level templates/ dir.

This is a self-contained artifact: it ships its own pnpm-lock.yaml, .npmrc, and
LICENSE and pins @Shopify/hydrogen to the published "preview" tag, so it runs on
its own when copy-pasted into a fresh repo by the build pipeline. It is not a
workspace member (templates/ is outside the pnpm-workspace globs), so it is
ignored by install/build/typecheck/test/lint. Add templates/** to the oxfmt
ignore list (mirroring the source repo) so format:check does not touch generated
output. Nothing under examples/ is changed.

One-off manual import from the storefront-kit generator; future imports will be
automated.
@mdamjanic7 mdamjanic7 force-pushed the react-router-rr8-template branch from 717c875 to 132b4aa Compare June 25, 2026 03:54
@mdamjanic7 mdamjanic7 changed the title examples/react-router: standalone RR8 storefront template templates/react-router: add standalone RR8 storefront template Jun 25, 2026
@mdamjanic7 mdamjanic7 self-assigned this Jun 25, 2026

@frandiox frandiox left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Misha! Problem: This template is not compatible with Oxygen. Please check the main branch template/skeleton to see how it works. It needs server.ts, oxygen() vite plugin, different dependencies, and different scripts to run/build.

Also, once this PR is released, this template should be updated like this.

The React Router template is what the "Deploy to Oxygen" button installs, so it
must run on Oxygen (workerd). It was a plain React Router 8 Node app and could
not deploy. This converts it to the Oxygen worker runtime while staying on RR8
and the framework-agnostic @Shopify/hydrogen (preview) library — no classic
Hydrogen (which hard-pins react-router@7.14.0).

- Add server.ts (module fetch worker entry: createRequestHandler from
  react-router + a RouterContextProvider) and worker SSR entries
  (app/entry.server.tsx via renderToReadableStream, app/entry.client.tsx).
- vite.config.ts: add @shopify/mini-oxygen oxygen() (RR-agnostic); no classic
  hydrogen() plugin. Scripts -> shopify hydrogen dev/build/preview.
- Deliver runtime env via the worker `env` binding instead of process.env:
  server.ts stashes env on the RouterContext; root middleware reads it and
  builds the request-scoped Storefront client (app/lib/env.ts, env.d.ts,
  app/lib/storefront.ts, app/lib/shop.ts). NODE_ENV stays (Vite inlines it).
- Deps: add @shopify/cli, @shopify/mini-oxygen, @shopify/oxygen-workers-types;
  drop @react-router/node and @react-router/serve. Regenerate the standalone
  pnpm-lock.yaml.
- README: document the Hydrogen/Oxygen workflow. Track .env.example (force-add;
  the repo .gitignore's .env.* rule was excluding it, so the README's
  `cp .env.example .env` would have failed in a deployed copy).

Verified: `shopify hydrogen build` (standalone, npm preview lib) produces the
worker; it boots and SSR-renders the home page (HTTP 200) in workerd with
MOCK_SHOP via the env binding; `pnpm typecheck` (tsc + gql.tada) is clean.
…npm)

Replace the RR8 chassis with the proven, Oxygen-deployable React Router 7 +
classic Hydrogen + Oxygen template, verified end-to-end (npm install + build +
`shopify hydrogen deploy` green on Oxygen).

- React Router 7.14.0 (the exact @shopify/hydrogen-classic peer; npm-strict-safe)
  + classic hydrogen() + oxygen() Vite plugins; buildDirectory "dist".
- Worker entry (server.ts), Web-Streams server/client entries, worker env typing.
- Storefront mode auto-detects: real store when PRIVATE_STOREFRONT_API_TOKEN is
  present (Oxygen injects it + PUBLIC_STORE_DOMAIN for a linked storefront),
  mock.shop fallback otherwise, so a fresh deploy always renders. MOCK_SHOP=1
  forces mock.
- npm-flavored: ships package-lock.json (the Oxygen workflow runs `npm ci`),
  npm README; pnpm-lock.yaml dropped.
- patch-hydrogen-exports.mjs (postinstall): temporary shim adding the missing
  "./package.json" export to @Shopify/hydrogen so `shopify hydrogen deploy`
  builds under npm. Remove once the lib ships that export.
@mdamjanic7 mdamjanic7 changed the title templates/react-router: add standalone RR8 storefront template templates/react-router: add standalone RR7 storefront template Jun 26, 2026
@mdamjanic7 mdamjanic7 merged commit d9b92fa into preview Jun 26, 2026
3 checks passed
@mdamjanic7 mdamjanic7 deleted the react-router-rr8-template branch June 26, 2026 20:58
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.

2 participants