feat!: vite 7 support to mini-oxygen#3493
feat!: vite 7 support to mini-oxygen#3493ramonclaudio wants to merge 12 commits intoShopify:mainfrom
Conversation
|
I have signed the CLA! |
fredericoo
left a comment
There was a problem hiding this comment.
we have just now finished migrating from npm to pnpm
can you merge main into this branch and revisit a few parts:
- overrides no longer exists in package.json
- do we need to override vite’s version? which peer/transitive deps could break because of this?
Fixes Shopify#3263 Vite 7 changed the Module Runner API in ways that break mini-oxygen's SSR evaluation. This adds the missing ssrExportNameKey (6th param), handles the new getBuiltins() invoke method, removes the deprecated root option from ModuleRunnerOptions, and bumps all vite peer deps across the monorepo. Also adds a migration guide and fixes the outdated Node version in CONTRIBUTING.md. Co-authored-by: Thomas Cristina de Carvalho <thomas@frontvibe.com>
hydrogen-react has zero runtime Vite dependency — the built output contains no import.meta, HMR, or Vite globals. Widening the peer dep to ^5.1.0 || ^6.2.1 || ^7.0.0 is non-breaking for existing users. Split into a separate changeset to avoid inheriting the inaccurate "Vite 5 and 6 support removed" CHANGELOG description.
0830857 to
6f489f5
Compare
All workspace packages already declare vite@^7.0.0 directly. The ^6.2.1 override (carried over from the npm->pnpm migration) would have forced vite 6.x across the workspace, breaking the Vite 7 upgrade.
Lockfile was stale after removing the vite ^6.2.1 workspace override in 134a1a5. Regenerated to resolve vite 7.x versions workspace-wide.
|
Done @fredericoo. Also regenerated |
|
Bumped |
Storefronts depend on @shopify/cli, not @shopify/cli-hydrogen directly.
- Remove fabricated npm 11.6.2+ prerequisite from upgrade guide - Remove misleading Vitest section (was already required before Vite 7) - Change npm commands to pnpm in upgrade guide and changeset - Use workspace:^ instead of workspace:* in cli-hydrogen peerDeps to publish as caret ranges (matching previous behavior)
- Vitest ^3.2.4 was already required before Vite 7 - "Why Vite 7 only?" section was internal engineering detail, not merchant-facing
fredericoo
left a comment
There was a problem hiding this comment.
last round! it all passes tests and i could manually assure it all works fine on vite 7.
|
@ramonclaudio hey! thanks a lot for the work here. I was checking the new Vite's environment API and it seems like it would allow us to support Vite 8 without breaking changes for Vite 6 and 7. There's a draft here. Would you be able to check that PR and see if it works for your project? 🙏 |
|
Hey @frandiox. The Vite Environment API approach is the right call here. I went ahead and built Tested on a real storefront using the shopify-hydrogen-shadcn-template, my open source port of the default Build and dev server pass on Vite 6.4.1, 7.3.1, and 8.0.3. All routes 200 with live Storefront API data. HMR works. Zero console errors. I also added pnpm patches to my patches repo, if you want to test the changes on another project: |
|
@ramonclaudio Amazing, thank you so much for the thorough test! 🙇 |
|
@frandiox NP. Happy to help! |
WHY are these changes introduced?
Fixes #3263
I opened #3263 in October when Vite 7 broke mini-oxygen with
ReferenceError: __vite_ssr_exportName__ is not defined. @thomasKn opened #3417 in January with a fix, but @frandiox suggested waiting for #3404 (Node version bump) to merge first. #3404 merged on Feb 17 but #3417 was never rebased, and now it conflicts with 62 commits that landed since (the 2026.1.0 release, security dep bumps, calver infrastructure changes, the docs/preview migration to React Router 7, etc).the core
worker-entry.tsfix in #3417 was correct so this PR applies the same approach rebased on current main. @thomasKn is credited as co-author on the commit.from thomasKn's #3417:
ssrExportNameKeyand use all 6 SSR context keys in explicit ordergetBuiltins()invoke method (returns empty array for workerd)rootfromModuleRunnerOptionsand__VITE_ROOTfrom bindingsadded in this PR:
fetchModule()dispatch to route bycustomData.nameinstead of treating every custom invoke as a fetch. the old code also had a bug where it passed the method name ("fetchModule") as the importer param instead of the actual importer fromcustomData.data[1]docs/upgrade-guides/upgrading-to-vite-7.mddocs/preview/package.jsonto Vite 7 (missed in Upgrade to Vite 7 (breaking change) #3417)packages/cli/assets/vite/package.jsonto Vite 7 soshopify hydrogen setup vitedoesn't scaffold a Vite 6 project that immediately breaksworkspace:*toworkspace:^in cli-hydrogen peerDeps so they publish as caret ranges (matching previous behavior)the root cause: Vite 7 added
ssrExportNameKeyas a 6th parameter torunInlinedModule. mini-oxygen was usingObject.keys(context)to build the parameter list, which worked in Vite 5/6 (5 params) but breaks in Vite 7 because the parameter ordering no longer matches what the transformed SSR code expects.Vite 7 also removed the
rootoption fromModuleRunnerOptionsand added agetBuiltins()invoke method. both need handling.WHAT is this pull request doing?
packages/mini-oxygen/src/vite/worker-entry.ts:vite/module-runner(ssrModuleExportsKey,ssrImportMetaKey,ssrImportKey,ssrDynamicImportKey,ssrExportAllKey,ssrExportNameKey) and pass them in explicit order instead ofObject.keys(context)/Object.values(context)getBuiltins()invoke method (returns empty array, no builtins in workerd)fetchModule()dispatch to usecustomData.namematching and fix the importer bugrootfromModuleRunnerOptions(removed in Vite 7)__VITE_ROOTfromViteEnvinterfacepackages/mini-oxygen/src/vite/server-middleware.ts:__VITE_ROOTbindingpackages/cli/src/commands/hydrogen/build.test.ts:building for productionis nowbuilding client environment for production,building SSR bundle for productionis nowbuilding ssr environment for productionversion bumps across 6 package.json files. vite peer/dev deps updated from various Vite 5/6 ranges (
^5.1.0 || ^6.2.x,^6.2.x, etc) to^7.0.0. vitest and @vitest/coverage-v8 bumped from^1.0.4to^3.2.4in cli-hydrogen.also:
docs/upgrade-guides/upgrading-to-vite-7.mdbefore:
after:
HOW to test your changes?
cli-hydrogen: 315 passed, 6 skipped, 0 failures. full suite across all packages: 1,318 passed, 12 skipped, 0 failures. typecheck/lint/format clean.
Notes
Vite 5 and 6 support is dropped. the module runner parameter structure changed from 5 to 6 params with no backwards-compatible way to detect which version you're on at build time.
@frandiox mentioned migrating to the Vite Environment API eventually. that's a separate thing. this just gets people off the
__vite_ssr_exportName__error.Checklist