fix(examples): run the poc examples with zero setup + stop the dev-server race - #3825
Open
div-cowboy wants to merge 2 commits into
Open
fix(examples): run the poc examples with zero setup + stop the dev-server race#3825div-cowboy wants to merge 2 commits into
div-cowboy wants to merge 2 commits into
Conversation
div-cowboy
force-pushed
the
fix/examples-private-token-fallback
branch
from
June 30, 2026 22:06
4770627 to
c27c7fa
Compare
Author
|
I have signed the CLA! |
Author
Contributor
`pnpm dev` runs `@shopify/hydrogen#build` (one-shot, via turbo `^build`) and then `@shopify/hydrogen#dev` (`tsdown --watch`). The watch's default startup clean wipes the just-built `dist/` while the example bundlers are reading it, spewing transient "Module not found: Can't resolve '@shopify/hydrogen'" at every example. Disable clean in `--watch` mode only: `dist/` stays populated from the build, rolldown writes each output atomically, so example bundlers always resolve a complete module. Production builds still clean; SDK hot reload is preserved (verified: edit src -> tsdown rebuilds -> example reloads). This replaces the dev-script workaround from Shopify#3826 (which removed the watch and so lost SDK hot reload). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…lback The framework examples (nextjs, react-router) fall back to mock.shop when no PRIVATE_STOREFRONT_API_TOKEN is provisioned, so a fresh clone renders. The five poc examples still called getPrivateStorefrontToken(), which throws — so every SSR request 500s for anyone who cannot decrypt the ejson secrets. Add examples/shared/storefront-config.ts, a shared resolver applying the same mock.shop fallback the framework examples established, and route astro, nuxt, nuxt-binding, solid-start and sveltekit through it. mock.shop accepts the well-known `mock-private-token` for the private-client auth header, so the examples keep `type: "private"` and the request-scoped client contract their handlers and loaders are typed against. Customer Accounts remain unavailable on mock.shop; the poc account pages already degrade to their signed-out state, so handler registration is left as-is.
div-cowboy
force-pushed
the
fix/examples-private-token-fallback
branch
from
July 31, 2026 14:43
e21a15a to
9bac319
Compare
Author
|
@fredericoo Awesome. I just rebased and squashed all the conflicts. There was some stuff that was incorporated from other PRs, so I trimmed the fat and updated the PR description. |
Author
|
bump |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TL;DR: This PR was opened before the recent
previewrefactor, which independently landed most of it (env-var token reads, a mock.shop fallback for the framework examples, per-example dev scripts, and thedev:hubport allocator). It is now rebased onto currentpreview. What remains is the dev-server race fix, plus extending the mock.shop zero-setup fallback to the fivepoc/examples that still throw without a private token.Before
Two things break a fresh clone of
preview:The five
examples/poc/*apps throw on every SSR request:examples/nextjsandexamples/react-routeralready fall back to mock.shop, but the poc ports still callgetPrivateStorefrontToken(), which throws. Anyone outside Shopify cannot decrypt the ejson secrets, so those five apps cannot be run at all.pnpm devprints a wall of transient errors before settling:After
What this changes
Zero-setup fallback for the poc examples
examples/shared/storefront-config.ts.resolveStorefrontConfig(exampleName, env?)returns the configured store whenPRIVATE_STOREFRONT_API_TOKENis present, and otherwise returnsmock.shopwith its well-knownmock-private-token. It warns once per process.poc/astro,poc/nuxt,poc/nuxt-binding,poc/solid-startandpoc/sveltekitnow build their client through it.envargument keeps SvelteKit's$env/dynamic/privateworking, whereprocess.envis not populated.mock-private-tokenfor the private-client auth header, so the examples keeptype: "private". The request-scoped private client contract their handlers and loaders are typed against is unchanged.Stop the SDK watch from racing the example bundlers
pnpm devruns both@shopify/hydrogen#build(one-shot, via turbo^build) and@shopify/hydrogen#dev(tsdown --watch). The watch's default startup clean wipes the just-builtdist/while the example bundlers are reading it through the workspace symlink.packages/hydrogen/tsdown.config.tsnow skips the clean in--watchmode only. Production builds still clean.Measured locally by sampling
dist/during watch startup: with the current config the file count drops from 563 to 0; with this change it never drops below 563.Developer impact
No changeset. The only
packages/hydrogenchange is dev-only build configuration, and production output is unchanged (tsdown already defaults toclean: true, so the non-watch path is identical). Everything else lives underexamples/, which.changeset/config.jsonignores.Out of scope
examples/nextjsandexamples/react-routergate theirs; doing the same for the poc ports would mean adding notice UI to five apps.examples/nextjsandexamples/react-routerkeep their own local resolvers because they also gate Customer Accounts on the same signal.scripts/examples-dev.ts(pnpm dev:hub) now allocates ports and passes--port, so hardcoding one in eachdevscript would fight it. Dropped.Risk
hydrogen-preview, so pages that depend on store-specific data may render empty rather than erroring. This is the same tradeoff already accepted forexamples/nextjsandexamples/react-router.How to Test
Zero-setup fallback (no secrets required)
pnpm install.pnpm --filter @shopify/hydrogen-example-astro dev.[hydrogen-example-astro] No PRIVATE_STOREFRONT_API_TOKEN found — running against mock.shop (mock.shop).@shopify/hydrogen-example-nuxt,-nuxt-binding,-solid-startand-sveltekit.Dev-server race
pnpm devfrom the repo root.Module not found: Can't resolve '@shopify/hydrogen'lines.