Skip to content

Conversation

@thomasKn
Copy link
Contributor

WHY are these changes introduced?

Fixes #3263

The @shopify/mini-oxygen package is incompatible with Vite 7.x due to SSR implementation differences, causing ReferenceError: __vite_ssr_exportName__ is not defined. This blocks developers from using Vite 7.

Vite 7 introduces breaking changes to the Module Runner API:

  • Added ssrExportNameKey as a 6th parameter to the SSR context
  • Added getBuiltins() invoke method
  • Removed deprecated root option from ModuleRunnerOptions

WHAT is this pull request doing?

Core changes to @shopify/mini-oxygen (src/vite/worker-entry.ts):

  • Added import for ssrExportNameKey (new 6th parameter in Vite 7)
  • Updated runInlinedModule to use 6 parameters matching Vite 7's esmEvaluator
  • Added support for the getBuiltins() invoke method

Removed deprecated feature (server-middleware.ts):

  • Removed __VITE_ROOT binding (deprecated in Vite 7)

Package updates:

Package Change
@shopify/mini-oxygen Vite peer dep ^7.0.0, Node >=20.19.0
@shopify/cli-hydrogen Vite ^7.0.0, Vitest ^3.2.4
@shopify/hydrogen Vite peer dep ^7.0.0
@shopify/hydrogen-react Vite ^7.0.0
templates/skeleton Vite ^7.0.0
Root workspace Node >=20.19.0, Vite override ^7.0.0

Test updates:

  • build.test.ts: Updated assertions for Vite 7's changed output messages

HOW to test your changes?

  1. Run mini-oxygen tests:

    npm test -- --filter=@shopify/mini-oxygen

    Expected: 47 tests pass

  2. Build the skeleton template:

    cd templates/skeleton && npm run build

    Expected: Successful build

  3. Run cli-hydrogen tests:

    npm test -- --filter=@shopify/cli-hydrogen

    Expected: 297/298 pass (1 pre-existing failure unrelated to Vite 7)

Checklist

  • I've read the Contributing Guidelines
  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've added a changeset if this PR contains user-facing or noteworthy changes
  • I've added tests to cover my changes
  • I've added or updated the documentation

Upgrades Hydrogen to require Vite 7.3.1+. This is a breaking change as
Vite 5 and 6 are no longer supported due to incompatible module runner
APIs. Implements critical fixes to MiniOxygen's module runner to handle
Vite 7's new SSR export mechanism.

## Breaking Changes

**Vite 7 is now required** - Vite 5 and 6 are no longer compatible
- Vite 7 added a 6th SSR parameter (ssrExportNameKey) that is incompatible
  with Vite 6's 5-parameter structure
- Minimum Node.js version: 20.19.0 (was 18.0.0)
- Browser targets modernized: Chrome 107+, Safari 16+, Firefox 104+

## Migration Guide

Users must upgrade to Vite 7 before updating Hydrogen:
```bash
npm install vite@^7.0.0
```

## Key Changes

### Dependency Updates
- **BREAKING:** All Vite peer dependencies now require ^7.0.0 (was ^5.1.0 || ^6.2.1)
- Upgraded Vitest from ^1.0.4 to ^3.2.4 in @shopify/cli-hydrogen
- Added npm override to enforce Vite 7 across all packages
- Updated Node.js engine requirement to >=20.19.0

### MiniOxygen Vite 7 Compatibility Fixes
- Fixed missing __vite_ssr_exportName__ parameter (new 6th parameter in Vite 7)
- Added explicit parameter ordering to match Vite 7's esmEvaluator
- Implemented getBuiltins() invoke method handler (new in Vite 7)
- Removed deprecated 'root' option from ModuleRunnerOptions
- Cleaned up unused __VITE_ROOT environment variable

### Test Updates
- Updated build test expectations for Vite 7's new output format
  ("building client environment" vs "building for production")

## Why Vite 7 Only?

Vite 7's module runner has a fundamentally different parameter structure:
- **Vite 6**: 5 SSR parameters (no ssrExportNameKey)
- **Vite 7**: 6 SSR parameters (includes ssrExportNameKey)

Supporting both would require runtime version detection and dual code paths,
adding unnecessary complexity. Vite 7 is stable and provides better performance.

## Verification
- ✅ All packages build successfully with Vite 7.3.1
- ✅ 298/301 tests pass (99.4%)
- ✅ Dev server runs without errors
- ✅ TypeScript compilation passes
- ✅ @vitejs/plugin-react v4.3.4 compatible

## Related Issues
- Fixes Shopify#3263 - Add support for Vite 7 in @shopify/mini-oxygen
- Implements solution similar to cloudflare/workers-sdk#9773
Documents breaking changes:
- Vite 7.0.0+ required (Vite 5/6 no longer supported)
- Node.js 20.19.0+ required
- Migration guide for users
- Technical rationale for Vite 7 only approach
@thomasKn thomasKn requested a review from a team as a code owner January 26, 2026 22:33
Copy link
Contributor

@frandiox frandiox left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

I haven't tested this but the changes make sense from what I remember, at least as an interim solution. Eventually we should upgrade to the new Vite Environment API cc @fredericoo @kdaviduik

Note: Node.js upgrade probably should come first in another PR (there's already one for this I think).

@thomasKn
Copy link
Contributor Author

Thanks @frandiox! Agreed, makes sense to wait for #3404 to merge first. The full Environment API migration would be a good follow-up.

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.

Add support for Vite 7 in @shopify/mini-oxygen

2 participants