Skip to content

Conversation

@danielroe
Copy link
Member

🔗 Linked issue

📚 Description

this ports some changes from #33262 to make the diff more straightforward

@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@coderabbitai
Copy link

coderabbitai bot commented Oct 6, 2025

Walkthrough

The changes shift several integrations to environment-scoped Vite plugins. IslandsTransformPlugin is registered with prepend: true. Nitro now injects a client-only Vite plugin to alias vue to the runtime-compiler build. ResolveDeepImportsPlugin computes and caches per-environment resolve conditions and uses them during resolveId. ResolvedExternalsPlugin moves to applyToEnvironment, conditionally building externals for production SSR using Nitro data. Vite server config gains environments.ssr.resolve.conditions sourced from Nitro exportConditions. Nuxt core plugin registrations are de-scoped and reordered with prepend where applicable. Minor formatting and import consolidations are applied, and the test fixture updates vite:extend usage and plugin enforce: 'pre'.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

  • Heterogeneous edits across multiple core areas (Nuxt core, Nitro, Vite server, plugins, tests)
  • Non-trivial lifecycle shifts to environment-scoped plugins and prepend/enforce ordering
  • New per-environment resolution logic and caching in resolve-deep-imports
  • Refactor of externals determination tied to Nitro state and production SSR conditions
  • Moderate file count with meaningful logic density; limited repetition

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title is concise and clearly highlights the core change of migrating plugin registrations to use the environment API in both Nuxt and Vite, aligning with the modifications in the changeset.
Description Check ✅ Passed The description specifies that the PR ports changes from a prior pull request to streamline the diff and directly relates to the refactoring work, fulfilling the lenient description requirement.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/vite

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c704151 and fbfd70b.

📒 Files selected for processing (8)
  • packages/nuxt/src/components/module.ts (1 hunks)
  • packages/nuxt/src/core/nitro.ts (2 hunks)
  • packages/nuxt/src/core/nuxt.ts (2 hunks)
  • packages/nuxt/src/core/plugins/resolve-deep-imports.ts (3 hunks)
  • packages/nuxt/src/core/plugins/resolved-externals.ts (1 hunks)
  • packages/nuxt/src/pages/plugins/page-meta.ts (1 hunks)
  • packages/vite/src/server.ts (1 hunks)
  • test/fixtures/basic/nuxt.config.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Follow standard TypeScript conventions and best practices

Files:

  • packages/nuxt/src/components/module.ts
  • packages/vite/src/server.ts
  • packages/nuxt/src/core/nuxt.ts
  • packages/nuxt/src/pages/plugins/page-meta.ts
  • packages/nuxt/src/core/plugins/resolved-externals.ts
  • packages/nuxt/src/core/plugins/resolve-deep-imports.ts
  • packages/nuxt/src/core/nitro.ts
  • test/fixtures/basic/nuxt.config.ts
🧠 Learnings (2)
📚 Learning: 2024-11-05T15:22:54.759Z
Learnt from: GalacticHypernova
PR: nuxt/nuxt#26468
File: packages/nuxt/src/components/plugins/loader.ts:24-24
Timestamp: 2024-11-05T15:22:54.759Z
Learning: In `packages/nuxt/src/components/plugins/loader.ts`, the references to `resolve` and `distDir` are legacy code from before Nuxt used the new unplugin VFS and will be removed.

Applied to files:

  • packages/nuxt/src/core/nuxt.ts
📚 Learning: 2024-12-12T12:36:34.871Z
Learnt from: huang-julien
PR: nuxt/nuxt#29366
File: packages/nuxt/src/app/components/nuxt-root.vue:16-19
Timestamp: 2024-12-12T12:36:34.871Z
Learning: In `packages/nuxt/src/app/components/nuxt-root.vue`, when optimizing bundle size by conditionally importing components based on route metadata, prefer using inline conditional imports like:

```js
const IsolatedPage = route?.meta?.isolate ? defineAsyncComponent(() => import('#build/isolated-page.mjs')) : null
```

instead of wrapping the import in a computed property or importing the component unconditionally.

Applied to files:

  • packages/nuxt/src/pages/plugins/page-meta.ts
🧬 Code graph analysis (5)
packages/nuxt/src/components/module.ts (2)
packages/kit/src/build.ts (1)
  • addBuildPlugin (153-165)
packages/nuxt/src/components/plugins/islands-transform.ts (1)
  • IslandsTransformPlugin (32-143)
packages/nuxt/src/core/nuxt.ts (3)
packages/kit/src/build.ts (1)
  • addVitePlugin (137-145)
packages/nuxt/src/core/plugins/resolve-deep-imports.ts (1)
  • ResolveDeepImportsPlugin (13-79)
packages/nuxt/src/core/plugins/resolved-externals.ts (1)
  • ResolveExternalsPlugin (8-57)
packages/nuxt/src/core/plugins/resolved-externals.ts (1)
packages/kit/src/nitro.ts (1)
  • useNitro (78-84)
packages/nuxt/src/core/plugins/resolve-deep-imports.ts (2)
packages/kit/src/index.ts (1)
  • directoryToURL (43-43)
packages/kit/src/internal/esm.ts (1)
  • directoryToURL (13-15)
packages/nuxt/src/core/nitro.ts (1)
packages/kit/src/build.ts (1)
  • addVitePlugin (137-145)
🔇 Additional comments (3)
packages/nuxt/src/core/plugins/resolved-externals.ts (3)

2-2: Import change looks correct.

The addition of useNitro to the imports is necessary for accessing the Nitro instance.


15-35: Environment-aware externals logic is well-implemented.

The applyToEnvironment implementation correctly:

  • Returns false for dev mode or non-SSR environments, avoiding unnecessary work
  • Defers fetching Nitro runtime dependencies until needed
  • Constructs the external set with appropriate dependencies
  • Uses nitro.options.inlineDynamicImports for conditional Vue inclusion

The logic aligns with the PR objective of making plugins environment-aware.


8-10: Verify Nitro readiness in ResolveExternalsPlugin
Ensure the useNitro() call in ResolveExternalsPlugin runs only after the nitro:init hook (addVitePlugin callbacks should execute post-initialisation); if this isn’t guaranteed, defer useNitro() into a plugin hook (e.g. config or buildStart).

Comment on lines +19 to +31
const resolvedConditions = new Set([nuxt.options.dev ? 'development' : 'production', ...environment.config.resolve.conditions])
if (resolvedConditions.has('browser')) {
resolvedConditions.add('web')
resolvedConditions.add('import')
resolvedConditions.add('module')
resolvedConditions.add('default')
}
if (environment.config.mode === 'test') {
resolvedConditions.add('import')
resolvedConditions.add('require')
}
return [...resolvedConditions]
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Guard against missing resolve.conditions

environment.config.resolve.conditions can be undefined (e.g. when Nitro hasn’t populated export conditions yet), so spreading it throws TypeError: object is not iterable. Please default it to an empty array before constructing the Set, e.g. ...(environment.config.resolve.conditions ?? []), and reuse the same guard when caching in environmentConditions.

Also applies to: 62-68

🤖 Prompt for AI Agents
In packages/nuxt/src/core/plugins/resolve-deep-imports.ts around lines 19-31
(and similarly lines 62-68), spreading environment.config.resolve.conditions can
throw when it's undefined; change all occurrences to spread a safe default such
as ...(environment.config.resolve.conditions ?? []) when constructing
resolvedConditions (and when populating environmentConditions cache) so the code
uses an empty array if conditions is missing.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 6, 2025

Open in StackBlitz

@nuxt/kit

npm i https://pkg.pr.new/@nuxt/kit@33403

nuxt

npm i https://pkg.pr.new/nuxt@33403

@nuxt/rspack-builder

npm i https://pkg.pr.new/@nuxt/rspack-builder@33403

@nuxt/schema

npm i https://pkg.pr.new/@nuxt/schema@33403

@nuxt/vite-builder

npm i https://pkg.pr.new/@nuxt/vite-builder@33403

@nuxt/webpack-builder

npm i https://pkg.pr.new/@nuxt/webpack-builder@33403

commit: fbfd70b

@codspeed-hq
Copy link

codspeed-hq bot commented Oct 6, 2025

CodSpeed Performance Report

Merging #33403 will not alter performance

Comparing refactor/vite (fbfd70b) with main (c704151)

Summary

✅ 10 untouched

@danielroe danielroe merged commit 5eb356e into main Oct 6, 2025
49 checks passed
@danielroe danielroe deleted the refactor/vite branch October 6, 2025 14:43
@github-actions github-actions bot mentioned this pull request Oct 6, 2025
@github-actions github-actions bot mentioned this pull request Oct 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants