Repository navigation
feat(nitro,schema,vite): add experimental support for nitro/vite - #35604
Conversation
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
4302b0f to
e4d96cb
Compare
@nuxt/kit
@nuxt/nitro-server
nuxt
@nuxt/rspack-builder
@nuxt/schema
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
Merging this PR will not alter performance
Comparing Footnotes
|
9911b32 to
dd1f59f
Compare
dd1f59f to
1c81163
Compare
1c81163 to
529be72
Compare
| // TODO: fix upstream in nitro | ||
| // `nitro/vite` keeps `RunnerManager` in process-global state, so all but | ||
| // one concurrent worker gets a 503: 'Vite environment "nitro" is unavailable' | ||
| ...(entry.builder === 'nitro-vite' ? { fileParallelism: false } : {}), |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/nitro-server/src/index.ts`:
- Around line 489-496: Update the stub manifest construction in the build:before
hook to set its timestamp from the existing buildTimestamp variable instead of
generating a new Date.now() value, keeping it consistent with writeAppManifest
and latest.json.
In `@packages/nitro-server/src/runtime/utils/renderer/dev-css.ts`:
- Around line 13-22: The shared renderer manifest is being mutated with
request-specific development CSS, allowing concurrent requests to leak styles
into one another. Update patchDevClientCss in
packages/nitro-server/src/runtime/utils/renderer/dev-css.ts:13-22 to clone or
carry the CSS through request-local state instead of calling updateManifest on
the cached rendererContext; adjust the getRequestDependencies flows at
packages/nitro-server/src/runtime/handlers/renderer.ts:157-160 and
packages/nitro-server/src/runtime/handlers/island.ts:81-86 to consume that
request-local manifest.
In `@packages/vite/src/plugins/client-manifest.ts`:
- Around line 48-69: Update buildDevClientManifest so the envApi branch
constructs the client entry as /@fs${clientEntry}, preserving the existing
clientEntry value for non-envApi builds and the rest of the manifest behavior.
In `@test/matrix.ts`:
- Line 4: Update the TEST_BUILDER fallback in the builder declaration to use a
falsy-value fallback so an empty environment variable resolves to 'vite' instead
of producing an invalid empty builder.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 205bb9a9-4f38-45fb-a172-92e16a149dcf
⛔ Files ignored due to path filters (3)
packages/nitro-server/package.jsonis excluded by!**/package.jsonpnpm-lock.yamlis excluded by!**/pnpm-lock.yaml,!pnpm-lock.yamltest/fixtures/nitro-vite-environment/package.jsonis excluded by!**/package.json
📒 Files selected for processing (34)
docs/3.guide/6.going-further/8.builders.mdpackages/kit/src/build.tspackages/nitro-server/src/index.tspackages/nitro-server/src/internal.d.tspackages/nitro-server/src/runtime/handlers/island.tspackages/nitro-server/src/runtime/handlers/renderer.tspackages/nitro-server/src/runtime/middleware/dev-client-css.tspackages/nitro-server/src/runtime/utils/renderer/dev-client-css.tspackages/nitro-server/src/runtime/utils/renderer/dev-css.tspackages/nitro-server/src/utils.tspackages/nitro-server/src/vite.tspackages/nuxt/src/core/nuxt.tspackages/nuxt/src/core/plugins/prehydrate.tspackages/nuxt/src/head/module.tspackages/schema/src/builder-env.tspackages/schema/src/config/experimental.tspackages/schema/src/types/schema.tspackages/ui-templates/styles.tspackages/vite/src/plugins/client-manifest.tspackages/vite/src/plugins/dev-server.tspackages/vite/src/plugins/resolved-externals.tspackages/vite/src/plugins/server-entry.tspackages/vite/src/plugins/ssr-styles.tspackages/vite/src/plugins/vite-node.tspackages/vite/src/shared/server.tspackages/vite/src/utils/css.tspackages/vite/src/vite.tstest/fixtures/dynamic-paths/nuxt.config.tstest/fixtures/nitro-vite-environment/app/app.vuetest/fixtures/nitro-vite-environment/nuxt.config.tstest/fixtures/nitro-vite-environment/tsconfig.jsontest/matrix.tstest/nitro-vite-environment.test.tsvitest.config.ts
💤 Files with no reviewable changes (1)
- packages/ui-templates/styles.ts
8c8f90a to
ef6d813
Compare
ef6d813 to
2e7193a
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/nitro-server/src/index.ts`:
- Around line 550-558: Update the virtual-module registration loop around
NUXT_BUILD_OUTPUT_MAP to handle the nuxt/styles entry separately: use
nuxt.buildOutputs.ssrStyles as a path and expose it through an appropriate
virtual-module export or alias, rather than invoking it as a function. Keep the
existing provider-function handling unchanged for all other mapped outputs and
preserve the existing exclusions.
- Around line 528-541: Update writeAppManifest so it always writes the refreshed
manifest, including actual prerendered routes, to tempDir as well as the
existing output directory when nitroViteEnvironment is enabled. Preserve the
current latest.json and meta/${buildId}.json generation while ensuring the
`#app-manifest` alias continues resolving to the updated tempDir manifest.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 8ac9b15f-7604-4c3b-9027-118417a95a79
⛔ Files ignored due to path filters (3)
packages/nitro-server/package.jsonis excluded by!**/package.jsonpnpm-lock.yamlis excluded by!**/pnpm-lock.yaml,!pnpm-lock.yamltest/fixtures/nitro-vite-environment/package.jsonis excluded by!**/package.json
📒 Files selected for processing (35)
docs/3.guide/6.going-further/8.builders.mdpackages/kit/src/build.tspackages/nitro-server/src/index.tspackages/nitro-server/src/internal.d.tspackages/nitro-server/src/runtime/handlers/island.tspackages/nitro-server/src/runtime/handlers/renderer.tspackages/nitro-server/src/runtime/middleware/dev-client-css.tspackages/nitro-server/src/runtime/utils/renderer/dev-client-css.tspackages/nitro-server/src/runtime/utils/renderer/dev-css.tspackages/nitro-server/src/utils.tspackages/nitro-server/src/vite.tspackages/nuxt/src/core/nuxt.tspackages/nuxt/src/core/plugins/prehydrate.tspackages/nuxt/src/head/module.tspackages/schema/src/builder-env.tspackages/schema/src/config/experimental.tspackages/schema/src/types/schema.tspackages/ui-templates/styles.tspackages/vite/src/plugins/client-manifest.tspackages/vite/src/plugins/dev-server.tspackages/vite/src/plugins/resolved-externals.tspackages/vite/src/plugins/server-entry.tspackages/vite/src/plugins/ssr-styles.tspackages/vite/src/plugins/vite-node.tspackages/vite/src/shared/server.tspackages/vite/src/utils/css.tspackages/vite/src/vite.tspnpm-workspace.yamltest/fixtures/dynamic-paths/nuxt.config.tstest/fixtures/nitro-vite-environment/app/app.vuetest/fixtures/nitro-vite-environment/nuxt.config.tstest/fixtures/nitro-vite-environment/tsconfig.jsontest/matrix.tstest/nitro-vite-environment.test.tsvitest.config.ts
💤 Files with no reviewable changes (1)
- packages/ui-templates/styles.ts
🚧 Files skipped from review as they are similar to previous changes (23)
- test/fixtures/nitro-vite-environment/nuxt.config.ts
- test/fixtures/nitro-vite-environment/tsconfig.json
- test/fixtures/nitro-vite-environment/app/app.vue
- packages/nuxt/src/head/module.ts
- packages/nitro-server/src/runtime/utils/renderer/dev-css.ts
- packages/nitro-server/src/runtime/middleware/dev-client-css.ts
- packages/nuxt/src/core/nuxt.ts
- packages/schema/src/builder-env.ts
- packages/vite/src/plugins/vite-node.ts
- packages/nuxt/src/core/plugins/prehydrate.ts
- packages/vite/src/plugins/dev-server.ts
- packages/schema/src/types/schema.ts
- packages/vite/src/utils/css.ts
- packages/nitro-server/src/runtime/handlers/island.ts
- packages/kit/src/build.ts
- test/fixtures/dynamic-paths/nuxt.config.ts
- test/matrix.ts
- packages/schema/src/config/experimental.ts
- packages/nitro-server/src/runtime/handlers/renderer.ts
- packages/vite/src/plugins/server-entry.ts
- packages/vite/src/plugins/ssr-styles.ts
- vitest.config.ts
- packages/vite/src/vite.ts
| const dir = nuxt.options.experimental.nitroViteEnvironment | ||
| ? join(nitro.options.output.publicDir, manifestPrefix) | ||
| : tempDir | ||
| await fsp.mkdir(join(dir, 'meta'), { recursive: true }) | ||
| await fsp.writeFile(join(dir, 'latest.json'), JSON.stringify({ | ||
| id: buildId, | ||
| timestamp: buildTimestamp, | ||
| })) | ||
| await fsp.writeFile(join(tempDir, `meta/${buildId}.json`), JSON.stringify(manifest)) | ||
| }) | ||
| await fsp.writeFile(join(dir, `meta/${buildId}.json`), JSON.stringify(manifest)) | ||
| } | ||
| // seed the manifest so `#app-manifest` resolves during bundling, | ||
| // and refresh it after prerendering with the actual prerendered routes | ||
| nitro.hooks.hook('rollup:before', writeAppManifest) | ||
| nitro.hooks.hook('prerender:done', writeAppManifest) |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🔴 Critical | ⚡ Quick win
Keep the #app-manifest alias source up-to-date.
When experimental.nitroViteEnvironment is enabled, writeAppManifest writes the updated manifest (with the actual prerendered routes) directly to nitro.options.output.publicDir.
However, the #app-manifest alias (configured on lines 486 and 502) still points to tempDir (<buildDir>/manifest/meta/<buildId>.json). Because tempDir is not updated after the build:before stub generation, any imports of #app-manifest during the build will read the stub manifest, resulting in missing prerendered routes in the bundled application.
Ensure the manifest in tempDir is also updated so that the alias resolves to the correct data.
🐛 Proposed fix
const dir = nuxt.options.experimental.nitroViteEnvironment
? join(nitro.options.output.publicDir, manifestPrefix)
: tempDir
await fsp.mkdir(join(dir, 'meta'), { recursive: true })
await fsp.writeFile(join(dir, 'latest.json'), JSON.stringify({
id: buildId,
timestamp: buildTimestamp,
}))
await fsp.writeFile(join(dir, `meta/${buildId}.json`), JSON.stringify(manifest))
+
+ if (dir !== tempDir) {
+ await fsp.writeFile(join(tempDir, `meta/${buildId}.json`), JSON.stringify(manifest))
+ }
}
// seed the manifest so `#app-manifest` resolves during bundling,
// and refresh it after prerendering with the actual prerendered routes📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const dir = nuxt.options.experimental.nitroViteEnvironment | |
| ? join(nitro.options.output.publicDir, manifestPrefix) | |
| : tempDir | |
| await fsp.mkdir(join(dir, 'meta'), { recursive: true }) | |
| await fsp.writeFile(join(dir, 'latest.json'), JSON.stringify({ | |
| id: buildId, | |
| timestamp: buildTimestamp, | |
| })) | |
| await fsp.writeFile(join(tempDir, `meta/${buildId}.json`), JSON.stringify(manifest)) | |
| }) | |
| await fsp.writeFile(join(dir, `meta/${buildId}.json`), JSON.stringify(manifest)) | |
| } | |
| // seed the manifest so `#app-manifest` resolves during bundling, | |
| // and refresh it after prerendering with the actual prerendered routes | |
| nitro.hooks.hook('rollup:before', writeAppManifest) | |
| nitro.hooks.hook('prerender:done', writeAppManifest) | |
| const dir = nuxt.options.experimental.nitroViteEnvironment | |
| ? join(nitro.options.output.publicDir, manifestPrefix) | |
| : tempDir | |
| await fsp.mkdir(join(dir, 'meta'), { recursive: true }) | |
| await fsp.writeFile(join(dir, 'latest.json'), JSON.stringify({ | |
| id: buildId, | |
| timestamp: buildTimestamp, | |
| })) | |
| await fsp.writeFile(join(dir, `meta/${buildId}.json`), JSON.stringify(manifest)) | |
| if (dir !== tempDir) { | |
| await fsp.writeFile(join(tempDir, `meta/${buildId}.json`), JSON.stringify(manifest)) | |
| } | |
| } | |
| // seed the manifest so `#app-manifest` resolves during bundling, | |
| // and refresh it after prerendering with the actual prerendered routes | |
| nitro.hooks.hook('rollup:before', writeAppManifest) | |
| nitro.hooks.hook('prerender:done', writeAppManifest) |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/nitro-server/src/index.ts` around lines 528 - 541, Update
writeAppManifest so it always writes the refreshed manifest, including actual
prerendered routes, to tempDir as well as the existing output directory when
nitroViteEnvironment is enabled. Preserve the current latest.json and
meta/${buildId}.json generation while ensuring the `#app-manifest` alias continues
resolving to the updated tempDir manifest.
| // with `nitroViteEnvironment` these specifiers provided by `NuxtBuildOutputsPlugin` | ||
| if (!nuxt.options.experimental.nitroViteEnvironment) { | ||
| for (const [specifier, key] of Object.entries(NUXT_BUILD_OUTPUT_MAP)) { | ||
| if (specifier === 'nuxt/entry-chunk' || specifier === 'nuxt/entry-ids') { | ||
| continue // already registered above in the virtual block | ||
| } | ||
| nitroConfig.virtual![specifier] = () => nuxt.buildOutputs[key]() | ||
| } | ||
| nitroConfig.virtual![specifier] = () => nuxt.buildOutputs[key]() | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win
Handle ssrStyles correctly as a path, not a function.
The NUXT_BUILD_OUTPUT_MAP includes nuxt/styles, which maps to ssrStyles. According to the documentation, ssrStyles is a string (path) or undefined, not a function like the other value providers. Calling nuxt.buildOutputs[key]() when key is 'ssrStyles' will throw a TypeError in the legacy Rollup path.
You should handle ssrStyles separately by either returning a virtual module code that exports from the path, or setting up an alias.
🐛 Proposed fix
// with `nitroViteEnvironment` these specifiers provided by `NuxtBuildOutputsPlugin`
if (!nuxt.options.experimental.nitroViteEnvironment) {
for (const [specifier, key] of Object.entries(NUXT_BUILD_OUTPUT_MAP)) {
if (specifier === 'nuxt/entry-chunk' || specifier === 'nuxt/entry-ids') {
continue // already registered above in the virtual block
}
+ if (key === 'ssrStyles') {
+ nitroConfig.virtual![specifier] = () => {
+ const path = nuxt.buildOutputs.ssrStyles
+ return path ? `export * from ${JSON.stringify(path)}` : 'export default {}'
+ }
+ continue
+ }
nitroConfig.virtual![specifier] = () => nuxt.buildOutputs[key]()
}
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // with `nitroViteEnvironment` these specifiers provided by `NuxtBuildOutputsPlugin` | |
| if (!nuxt.options.experimental.nitroViteEnvironment) { | |
| for (const [specifier, key] of Object.entries(NUXT_BUILD_OUTPUT_MAP)) { | |
| if (specifier === 'nuxt/entry-chunk' || specifier === 'nuxt/entry-ids') { | |
| continue // already registered above in the virtual block | |
| } | |
| nitroConfig.virtual![specifier] = () => nuxt.buildOutputs[key]() | |
| } | |
| nitroConfig.virtual![specifier] = () => nuxt.buildOutputs[key]() | |
| } | |
| // with `nitroViteEnvironment` these specifiers provided by `NuxtBuildOutputsPlugin` | |
| if (!nuxt.options.experimental.nitroViteEnvironment) { | |
| for (const [specifier, key] of Object.entries(NUXT_BUILD_OUTPUT_MAP)) { | |
| if (specifier === 'nuxt/entry-chunk' || specifier === 'nuxt/entry-ids') { | |
| continue // already registered above in the virtual block | |
| } | |
| if (key === 'ssrStyles') { | |
| nitroConfig.virtual![specifier] = () => { | |
| const path = nuxt.buildOutputs.ssrStyles | |
| return path ? `export * from ${JSON.stringify(path)}` : 'export default {}' | |
| } | |
| continue | |
| } | |
| nitroConfig.virtual![specifier] = () => nuxt.buildOutputs[key]() | |
| } | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/nitro-server/src/index.ts` around lines 550 - 558, Update the
virtual-module registration loop around NUXT_BUILD_OUTPUT_MAP to handle the
nuxt/styles entry separately: use nuxt.buildOutputs.ssrStyles as a path and
expose it through an appropriate virtual-module export or alias, rather than
invoking it as a function. Keep the existing provider-function handling
unchanged for all other mapped outputs and preserve the existing exclusions.
2e7193a to
524815f
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/vite/src/plugins/ssr-styles.ts (1)
207-216: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valuePrefer using the
environmentclosure variable for consistency.While
this.environment.nameis functionally correct within Vite 6 plugins, other hooks in this plugin (likegenerateBundle,renderChunk, andtransform) use theenvironment.namevariable captured from theapplyToEnvironment(environment)parameter. Usingenvironment.namehere ensures consistency across all plugin hooks.💡 Proposed refactor
- if (!envApi && this.environment.name === 'ssr') { + if (!envApi && environment.name === 'ssr') {🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/vite/src/plugins/ssr-styles.ts` around lines 207 - 216, Update the buildStart hook in the SSR styles plugin to use the closure-scoped environment.name from applyToEnvironment(environment) instead of this.environment.name, including the SSR condition and stylesPath resolution, while preserving the existing behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/vite/src/plugins/ssr-styles.ts`:
- Around line 207-216: Update the buildStart hook in the SSR styles plugin to
use the closure-scoped environment.name from applyToEnvironment(environment)
instead of this.environment.name, including the SSR condition and stylesPath
resolution, while preserving the existing behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: c0a069ae-ab1f-4cb5-b1bd-88bba2006698
⛔ Files ignored due to path filters (3)
packages/nitro-server/package.jsonis excluded by!**/package.jsonpnpm-lock.yamlis excluded by!**/pnpm-lock.yaml,!pnpm-lock.yamltest/fixtures/nitro-vite-environment/package.jsonis excluded by!**/package.json
📒 Files selected for processing (35)
docs/3.guide/6.going-further/8.builders.mdpackages/kit/src/build.tspackages/nitro-server/src/index.tspackages/nitro-server/src/internal.d.tspackages/nitro-server/src/runtime/handlers/island.tspackages/nitro-server/src/runtime/handlers/renderer.tspackages/nitro-server/src/runtime/middleware/dev-client-css.tspackages/nitro-server/src/runtime/utils/renderer/dev-client-css.tspackages/nitro-server/src/runtime/utils/renderer/dev-css.tspackages/nitro-server/src/utils.tspackages/nitro-server/src/vite.tspackages/nuxt/src/core/nuxt.tspackages/nuxt/src/core/plugins/prehydrate.tspackages/nuxt/src/head/module.tspackages/schema/src/builder-env.tspackages/schema/src/config/experimental.tspackages/schema/src/types/schema.tspackages/ui-templates/styles.tspackages/vite/src/plugins/client-manifest.tspackages/vite/src/plugins/dev-server.tspackages/vite/src/plugins/resolved-externals.tspackages/vite/src/plugins/server-entry.tspackages/vite/src/plugins/ssr-styles.tspackages/vite/src/plugins/vite-node.tspackages/vite/src/shared/server.tspackages/vite/src/utils/css.tspackages/vite/src/vite.tspnpm-workspace.yamltest/fixtures/dynamic-paths/nuxt.config.tstest/fixtures/nitro-vite-environment/app/app.vuetest/fixtures/nitro-vite-environment/nuxt.config.tstest/fixtures/nitro-vite-environment/tsconfig.jsontest/matrix.tstest/nitro-vite-environment.test.tsvitest.config.ts
💤 Files with no reviewable changes (1)
- packages/ui-templates/styles.ts
🚧 Files skipped from review as they are similar to previous changes (28)
- test/fixtures/nitro-vite-environment/tsconfig.json
- packages/nitro-server/src/runtime/middleware/dev-client-css.ts
- packages/nitro-server/src/internal.d.ts
- pnpm-workspace.yaml
- packages/nitro-server/src/runtime/utils/renderer/dev-client-css.ts
- packages/nuxt/src/core/nuxt.ts
- packages/vite/src/plugins/vite-node.ts
- packages/vite/src/plugins/dev-server.ts
- packages/schema/src/types/schema.ts
- test/fixtures/nitro-vite-environment/nuxt.config.ts
- packages/nitro-server/src/runtime/handlers/island.ts
- packages/vite/src/vite.ts
- packages/schema/src/builder-env.ts
- packages/nitro-server/src/runtime/utils/renderer/dev-css.ts
- packages/vite/src/utils/css.ts
- packages/nuxt/src/head/module.ts
- test/fixtures/nitro-vite-environment/app/app.vue
- packages/schema/src/config/experimental.ts
- packages/kit/src/build.ts
- vitest.config.ts
- test/fixtures/dynamic-paths/nuxt.config.ts
- packages/nitro-server/src/runtime/handlers/renderer.ts
- packages/nuxt/src/core/plugins/prehydrate.ts
- packages/vite/src/plugins/resolved-externals.ts
- test/matrix.ts
- packages/nitro-server/src/utils.ts
- packages/vite/src/plugins/server-entry.ts
- packages/nitro-server/src/index.ts
🔗 Linked issue
📚 Description
I'm not entirely happy with this so I'd like to sit with it for a bit, and would welcome review and testing.
this implements
nitro/viteplugin. the major challenges at the moment are around the builder outputs API, so see #35463, #35601 and #35576.we're currently doing some hacks regarding the app manifest and SSR styles, particularly in dev mode, that I would value feedback on.
the renderer itself doesn't change much because we already refactored it in #35422