-
Notifications
You must be signed in to change notification settings - Fork 400
feat: use vite environment API #3617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
a346ccc
9d09cd0
640413e
6d2b93b
d03b9d0
ed01667
bc22c8e
9872e79
72b84a9
2540800
0d81997
82a9261
9947984
f13fe7d
bd048f0
7af923d
e8adc4e
c7477e6
d715d11
5844d82
aad2855
204113b
42b7b77
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| --- | ||
| '@shopify/mini-oxygen': minor | ||
| '@shopify/hydrogen': minor | ||
| '@shopify/cli-hydrogen': minor | ||
| '@shopify/hydrogen-react': minor | ||
| 'skeleton': patch | ||
| '@shopify/create-hydrogen': patch | ||
| --- | ||
|
|
||
| Add support for Vite 7 and Vite 8. Hydrogen remains backwards-compatible with Vite 5+, while Mini Oxygen, the Hydrogen CLI, and Hydrogen React require Vite 6 or newer. | ||
|
|
||
| Mini Oxygen's dev server has been refactored to use the [Vite Environment API](https://vite.dev/guide/api-environment), which is the standard way to run non-browser runtimes in Vite. This replaces the previous custom middleware approach with a first-class `FetchableDevEnvironment`, improving compatibility with Vite's built-in HMR and module invalidation. | ||
|
|
||
| New Hydrogen projects created with `npm create @shopify/hydrogen` will default to Vite 8. The `vite-tsconfig-paths` plugin is no longer needed in the skeleton template since Vite 8 supports `resolve.tsconfigPaths` natively. | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned in OP, perhaps it would be good to sync with the RR7 folks and see if they add official support for Vite 8 as well. Mostly to remove warnings from the terminal, otherwise it already works. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,6 @@ | |
| "isbot": "^5.1.21" | ||
| }, | ||
| "devDependencies": { | ||
| "vite": "^6.2.0", | ||
| "vite-tsconfig-paths": "^4.3.1" | ||
| "vite": "^8.0.1" | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,12 @@ type BundleAnalyzerOptions = { | |
| minify?: (code: string, filepath: string) => Promise<string>; | ||
| }; | ||
|
|
||
| type BundleModuleInfo = { | ||
| code?: string; | ||
| renderedLength?: number; | ||
| originalLength?: number; | ||
| }; | ||
|
|
||
| export function hydrogenBundleAnalyzer(pluginOptions?: BundleAnalyzerOptions) { | ||
| let config: ResolvedConfig; | ||
|
|
||
|
|
@@ -86,9 +92,13 @@ export function hydrogenBundleAnalyzer(pluginOptions?: BundleAnalyzerOptions) { | |
| const resultError = await Promise.all( | ||
| modsToAnalyze.map(async (mod) => { | ||
| const relativeModId = relativePath(root, mod.id); | ||
| const modBundleInfo = workerFile.modules[mod.id]; | ||
| const modBundleInfo = workerFile.modules[mod.id] as | ||
| | BundleModuleInfo | ||
| | undefined; | ||
| const originalCodeBytes = | ||
| modBundleInfo?.originalLength ?? mod.code?.length ?? 0; | ||
| typeof modBundleInfo?.originalLength === 'number' | ||
| ? modBundleInfo.originalLength | ||
| : (mod.code?.length ?? 0); | ||
|
|
||
| let resultingCodeBytes = modBundleInfo?.renderedLength ?? 0; | ||
|
|
||
|
|
@@ -185,34 +195,20 @@ export function hydrogenBundleAnalyzer(pluginOptions?: BundleAnalyzerOptions) { | |
| }, | ||
| }; | ||
|
|
||
| bundle[BUNDLE_ANALYZER_JSON_FILE] = { | ||
| this.emitFile({ | ||
| type: 'asset', | ||
| fileName: BUNDLE_ANALYZER_JSON_FILE, | ||
| needsCodeReference: false, | ||
| source: JSON.stringify(metafile, null, 2), | ||
| names: [BUNDLE_ANALYZER_JSON_FILE], | ||
| originalFileNames: [BUNDLE_ANALYZER_JSON_FILE], | ||
| // name and originalFileName should be deprecated .. but | ||
| // for some reason, removing them breaks typescript check | ||
| name: BUNDLE_ANALYZER_JSON_FILE, | ||
| originalFileName: BUNDLE_ANALYZER_JSON_FILE, | ||
| }; | ||
| }); | ||
|
|
||
| bundle[BUNDLE_ANALYZER_HTML_FILE] = { | ||
| this.emitFile({ | ||
| type: 'asset', | ||
| fileName: BUNDLE_ANALYZER_HTML_FILE, | ||
| needsCodeReference: false, | ||
| source: injectAnalyzerTemplateData( | ||
| analysisTemplate, | ||
| JSON.stringify(metafile), | ||
| ), | ||
| names: [BUNDLE_ANALYZER_HTML_FILE], | ||
| originalFileNames: [BUNDLE_ANALYZER_HTML_FILE], | ||
| // name and originalFileName should be deprecated .. but | ||
| // for some reason, removing them breaks typescript check | ||
| name: BUNDLE_ANALYZER_HTML_FILE, | ||
| originalFileName: BUNDLE_ANALYZER_HTML_FILE, | ||
| }; | ||
| }); | ||
|
Comment on lines
-201
to
+211
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same functionality, just fixing some types |
||
| }, | ||
| } satisfies Plugin; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ import {handleMiniOxygenImportFail} from './mini-oxygen/common.js'; | |
| import {importLocal} from './import-utils.js'; | ||
|
|
||
| export async function createCpuStartupProfiler(root: string) { | ||
| type MiniOxygenType = typeof import('@shopify/mini-oxygen/node'); | ||
| type MiniOxygenType = typeof import('~/mini-oxygen/node/index.js'); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This type of change (here and in other files) is just a fix to remove build order requirement for TS types (before we needed mini-oxygen built before CLI, now it doesn't matter). It can be ignored for review. |
||
| const {createMiniOxygen} = await importLocal<MiniOxygenType>( | ||
| '@shopify/mini-oxygen/node', | ||
| root, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -137,7 +137,7 @@ | |
| "@testing-library/user-event": "^14.6.1", | ||
| "@types/react": "catalog:", | ||
| "@types/react-dom": "catalog:", | ||
| "@vitejs/plugin-react": "^4.3.4", | ||
| "@vitejs/plugin-react": "^6.0.1", | ||
| "@vitest/coverage-v8": "^3.2.4", | ||
| "cpy-cli": "^5.0.0", | ||
| "eslint": "9.19.0", | ||
|
|
@@ -160,13 +160,13 @@ | |
| "rimraf": "^6.0.1", | ||
| "ts-expect": "^1.3.0", | ||
| "typescript": "5.9.2", | ||
| "vite": "^6.4.2", | ||
| "vite": "^8.0.1", | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change in hydrogen-react means we start building it with Vite 8 |
||
| "vitest": "^3.2.4" | ||
| }, | ||
| "peerDependencies": { | ||
| "react": "^18.3.1 || ~19.0.3 || ~19.1.4 || ^19.2.3", | ||
| "react-dom": "^18.3.1 || ~19.0.3 || ~19.1.4 || ^19.2.3", | ||
| "vite": "^5.1.0 || ^6.2.1" | ||
| "vite": "^5.1.0 || ^6.2.1 || ^7.0.0 || ^8.0.0" | ||
| }, | ||
| "dependencies": { | ||
| "@google/model-viewer": "^4.0.0", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have any CI tests that prove this, and would catch a regression? Should we, if we're claiming this?