Skip to content

Conversation

@cernymatej
Copy link
Member

@cernymatej cernymatej commented Aug 24, 2025

📚 Description

Following up on #29971, this adds a warning for overriding internal functions in auto-imports, which were added dynamically via imports:sources. Currently, it is definePageMeta and defineRouteRules, but there will be more in #32300.

@cernymatej cernymatej requested a review from danielroe as a code owner August 24, 2025 20:12
@bolt-new-by-stackblitz
Copy link

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Aug 24, 2025

Open in StackBlitz

@nuxt/kit

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

nuxt

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

@nuxt/rspack-builder

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

@nuxt/schema

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

@nuxt/vite-builder

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

@nuxt/webpack-builder

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

commit: 647009e

@coderabbitai
Copy link

coderabbitai bot commented Aug 24, 2025

Walkthrough

  • Added exported preset arrays pagesImportPresets and routeRulesPresets (both InlinePreset[]) in packages/nuxt/src/pages/module.ts and exposed them via an imports:sources hook.
  • In packages/nuxt/src/imports/module.ts, introduced allNuxtPresets combining pagesImportPresets, routeRulesPresets, and existing default presets.
  • Replaced defaultImportSources/defaultImports usage with broader nuxtImportSources and nuxtImports derived from allNuxtPresets.
  • Regeneration and conflict-detection logic now checks nuxtImportSources/nuxtImports to skip or detect conflicts for names coming from any Nuxt preset (pages, routeRules, defaults).
  • Conditional appending of routeRulesPresets remains gated by nuxt.options.experimental.inlineRouteRules.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/nuxt/src/imports/module.ts (1)

146-154: Bug: this will warn for Nuxt’s own internal imports (false positives).

The current condition uses i.__nuxt_internal on the item being iterated, so it logs for the internal import itself (e.g. definePageMeta) rather than when a user import overrides it. You need to compare user-defined imports against the set of internal-import names, and skip logging for the internal entries themselves.

Proposed fix:

-        for (const i of (imports as ImportInternal[])) {
-          if (!defaultImportSources.has(i.from)) {
-            const value = i.as || i.name
-            if ((defaultImports.has(value) || i.__nuxt_internal) && (!i.priority || i.priority >= 0 /* default priority */)) {
-              const relativePath = isAbsolute(i.from) ? `${resolveToAlias(i.from, nuxt)}` : i.from
-              logger.error(`\`${value}\` is an auto-imported function that is in use by Nuxt. Overriding it will likely cause issues. Please consider renaming \`${value}\` in \`${relativePath}\`.`)
-            }
-          }
-        }
+        // Build a lookup of names reserved by Nuxt (defaults + dynamically-added internal ones)
+        const internalImportNames = new Set<string>(
+          (imports as ImportInternal[])
+            .filter(j => j.__nuxt_internal)
+            .map(j => j.as || j.name),
+        )
+
+        for (const i of (imports as ImportInternal[])) {
+          if (defaultImportSources.has(i.from)) { continue }
+          const value = i.as || i.name
+          const conflictsWithDefault = defaultImports.has(value)
+          const conflictsWithInternal = internalImportNames.has(value) && !i.__nuxt_internal
+          if ((conflictsWithDefault || conflictsWithInternal) && (!i.priority || i.priority >= 0 /* default priority */)) {
+            const relativePath = isAbsolute(i.from) ? `${resolveToAlias(i.from, nuxt)}` : i.from
+            logger.error(`\`${value}\` is an auto-imported function that is in use by Nuxt. Overriding it will likely cause issues. Please consider renaming \`${value}\` in \`${relativePath}\`.`)
+          }
+        }
🧹 Nitpick comments (7)
packages/nuxt/src/imports/utils.ts (3)

5-10: Docstring vs behaviour: this mutates the input, not “creates a new Import object”.

Either adjust the wording or clone before tagging to avoid surprising callers.

Option A — clarify doc:

- * Creates a new `Import` object marked as an internal Nuxt entity to be able to warn users when they override it.
+ * Marks the given `Import` object as an internal Nuxt entity (non-enumerable) so we can warn when users override it.

Option B — actually create a new object (keeps callers’ inputs immutable):

-export function createInternalImport (i: Import): Import {
-  return Object.defineProperty(i, '__nuxt_internal', { value: true, enumerable: false })
-}
+export function createInternalImport (i: Import): Import {
+  const clone = { ...i }
+  return Object.defineProperty(clone, '__nuxt_internal', { value: true, enumerable: false, configurable: false, writable: false })
+}

8-10: Return a narrowed type to avoid downstream casts.

You already export ImportInternal; returning it here removes the need to cast in consumers.

-export function createInternalImport (i: Import): Import {
+export function createInternalImport (i: Import): ImportInternal {
-  return Object.defineProperty(i, '__nuxt_internal', { value: true, enumerable: false })
+  return Object.defineProperty(i, '__nuxt_internal', { value: true, enumerable: false, configurable: false, writable: false }) as ImportInternal
}

9-9: Explicitly set configurable and writable to false for clarity.

Defaults are false, but being explicit communicates intent and prevents accidental mutation in future refactors.

-return Object.defineProperty(i, '__nuxt_internal', { value: true, enumerable: false })
+return Object.defineProperty(i, '__nuxt_internal', { value: true, enumerable: false, configurable: false, writable: false })
packages/nuxt/src/imports/module.ts (2)

151-151: Severity wording: consider logger.warn to align with “warning” in the PR title and intent.

Functionally the same, but matches the messaging and reduces noise for users.

-              logger.error(`\`${value}\` is an auto-imported function that is in use by Nuxt. Overriding it will likely cause issues. Please consider renaming \`${value}\` in \`${relativePath}\`.`)
+              logger.warn(`\`${value}\` is an auto-imported function that is in use by Nuxt. Overriding it will likely cause issues. Please consider renaming \`${value}\` in \`${relativePath}\`.`)

13-13: Import extension consistency for type-only imports.

import type ... from './utils.ts' is erased at emit; both with and without .ts typically work under NodeNext. Please ensure this is consistent with the rest of the repo’s TS imports (style often omits .ts for type-only).

If the repo prefers extension-less type imports, apply:

-import type { ImportInternal } from './utils.ts'
+import type { ImportInternal } from './utils'
packages/nuxt/src/pages/module.ts (2)

400-405: Also mark defineRouteRules as internal when the experimental flag is enabled.

If users override defineRouteRules they’ll hit the same class of issues as definePageMeta. Tagging it keeps the warning consistent.

-      if (nuxt.options.experimental.inlineRouteRules) {
-        imports.push({ name: 'defineRouteRules', as: 'defineRouteRules', from: resolve(runtimeDir, 'composables') })
-      }
+      if (nuxt.options.experimental.inlineRouteRules) {
+        imports.push(createInternalImport({ name: 'defineRouteRules', as: 'defineRouteRules', from: resolve(runtimeDir, 'composables') }))
+      }

22-22: Import extension consistency.

Same note as in imports/module.ts: consider omitting .ts for type-only/runtime-internal imports if that’s the project style.

-import { createInternalImport } from '../imports/utils.ts'
+import { createInternalImport } from '../imports/utils'
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 5d78366 and cf6d1ab.

📒 Files selected for processing (3)
  • packages/nuxt/src/imports/module.ts (2 hunks)
  • packages/nuxt/src/imports/utils.ts (1 hunks)
  • packages/nuxt/src/pages/module.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/imports/module.ts
  • packages/nuxt/src/imports/utils.ts
  • packages/nuxt/src/pages/module.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/imports/module.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/module.ts
🧬 Code graph analysis (2)
packages/nuxt/src/imports/module.ts (1)
packages/nuxt/src/imports/utils.ts (1)
  • ImportInternal (3-3)
packages/nuxt/src/pages/module.ts (1)
packages/nuxt/src/imports/utils.ts (1)
  • createInternalImport (8-10)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
  • GitHub Check: test-fixtures (windows-latest, built, vite, default, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (windows-latest, dev, vite, default, manifest-off, json, lts/-1)
  • GitHub Check: test-fixtures (windows-latest, dev, vite, default, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (windows-latest, built, vite, default, manifest-off, json, lts/-1)
  • GitHub Check: test-fixtures (windows-latest, built, vite, async, manifest-off, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, async, manifest-on, js, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, default, manifest-off, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, async, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, default, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, async, manifest-on, js, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, rspack, default, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, default, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, default, manifest-off, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, async, manifest-on, json, lts/-1)
  • GitHub Check: release-pkg-pr-new
  • GitHub Check: test-benchmark
  • GitHub Check: typecheck (windows-latest, bundler)
  • GitHub Check: typecheck (ubuntu-latest, bundler)
  • GitHub Check: test-size
  • GitHub Check: code

@codspeed-hq
Copy link

codspeed-hq bot commented Aug 24, 2025

CodSpeed Performance Report

Merging #33050 will not alter performance

Comparing cernymatej:fix-import-overriding-warning (647009e) with main (27dc1f2)

Summary

✅ 10 untouched benchmarks

@cernymatej cernymatej changed the title fix(nuxt): include core auto-imports from imports:extends in override warning fix(nuxt): include core auto-imports from imports:sources in override warning Aug 26, 2025
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: 0

🧹 Nitpick comments (3)
packages/nuxt/src/imports/utils.ts (3)

5-10: Clone instead of mutating; align implementation with the docstring and make the return type internal.

The JSDoc says “Creates a new … object”, but the function mutates the argument in place. Cloning avoids side effects and makes behaviour match the description. Also, returning InternalImportPresetWithDeprecation removes the need for downstream casts.

Apply this diff:

 /**
- * Creates a new `ImportPresetWithDeprecation` object marked as internal to be able to warn users when they override it.
+ * Create a copy of the preset marked as internal (non-enumerable flag).
+ * Avoids mutating the original and lets us warn when it is overridden.
  */
-export function createInternalImportPresetWithDeprecation (i: ImportPresetWithDeprecation): ImportPresetWithDeprecation {
-  return Object.defineProperty(i, '__nuxt_internal', { value: true, enumerable: false })
-}
+export function createInternalImportPresetWithDeprecation (i: ImportPresetWithDeprecation): InternalImportPresetWithDeprecation {
+  const preset = { ...i } as InternalImportPresetWithDeprecation
+  Object.defineProperty(preset, '__nuxt_internal', { value: true, enumerable: false, configurable: false, writable: false })
+  return preset
+}

3-3: Make the internal flag readonly in the type.

The property is non-writable at runtime; reflect that intent in the type for better signalling and safety.

-export type InternalImportPresetWithDeprecation = ImportPresetWithDeprecation & { __nuxt_internal?: true }
+export type InternalImportPresetWithDeprecation = ImportPresetWithDeprecation & { readonly __nuxt_internal?: true }

5-10: Optional: provide a type guard to centralise detection of internal presets.

This avoids ad-hoc casts at call sites and keeps the flag name in one place.

Add the following helper near this util:

export function isInternalImportPresetWithDeprecation(
  p: ImportPresetWithDeprecation
): p is InternalImportPresetWithDeprecation {
  return Object.prototype.hasOwnProperty.call(p, '__nuxt_internal')
}

If you want, I can push a follow-up patch updating the call sites to use this guard instead of array casts.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between cf6d1ab and 494c8ef.

📒 Files selected for processing (3)
  • packages/nuxt/src/imports/module.ts (2 hunks)
  • packages/nuxt/src/imports/utils.ts (1 hunks)
  • packages/nuxt/src/pages/module.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/nuxt/src/pages/module.ts
  • packages/nuxt/src/imports/module.ts
🧰 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/imports/utils.ts
🧠 Learnings (1)
📓 Common learnings
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.
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.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: code

@cernymatej
Copy link
Member Author

I've updated the implementation. I haven't benchmarked it, I feel like this isn't going to be more performant 😕
I'm not really sure what you mean by hard-coding it... The packages/nuxt/src/pages/runtime/composables.ts file, from which the definePageMeta function originates, isn't exposed under any alias (AFAIK), so we can't just test for #app as I wanted to initially 🤔

I'll need to add more core auto-imports in #32300 from a module too.

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: 2

🧹 Nitpick comments (2)
packages/nuxt/src/imports/module.ts (2)

13-13: Avoid .ts extension in source imports to keep build outputs portable

Prefer extensionless import to prevent ESM resolution issues post-transpile and to align with repo style.

-import { distDir } from '../dirs.ts'
+import { distDir } from '../dirs'

15-15: Tighten #app detection regex

Use an explicit end-or-slash to avoid edge-case matches like #appConfig.

-const NUXT_APP_RE = /^#app\b/
+const NUXT_APP_RE = /^#app(?:$|\/)/
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 494c8ef and 097c591.

📒 Files selected for processing (1)
  • packages/nuxt/src/imports/module.ts (4 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/imports/module.ts
🧠 Learnings (2)
📓 Common learnings
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.
📚 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/imports/module.ts
🧬 Code graph analysis (1)
packages/nuxt/src/imports/module.ts (2)
packages/kit/src/resolve.ts (1)
  • resolvePath (52-63)
packages/nuxt/src/utils.ts (2)
  • resolveToAlias (16-18)
  • logger (14-14)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build
  • GitHub Check: code
🔇 Additional comments (2)
packages/nuxt/src/imports/module.ts (2)

2-2: LGTM on adding resolvePath import

This is appropriate for later resolution checks.


173-184: Review comment update

Change the conflict log to a warning and use the isFromNuxtDistPath check:

           const value = i.as || i.name
           if (
             (nuxtImportNames.has(value) || nuxtImportNamesFromPresets.has(value))
-            && !((await resolvePath(i.from)).startsWith(distDir))
+            && !(await isFromNuxtDistPath(i.from))
             && (!i.priority || i.priority >= 0)
           ) {
             const relativePath = isAbsolute(i.from) ? resolveToAlias(i.from, nuxt) : i.from
-            logger.error(`\`${value}\` is an auto-imported function that is in use by Nuxt. Overriding it will likely cause issues. Please consider renaming \`${value}\` in \`${relativePath}\`.`)
+            logger.warn(`\`${value}\` is an internal Nuxt auto-import. Overriding it will likely cause issues. Please consider renaming \`${value}\` in \`${relativePath}\`.`)
           }

Ensure isFromNuxtDistPath is imported and logger.warn is available in this module.

@danielroe
Copy link
Member

I was thinking more something like this - do you see any downsides?

@cernymatej
Copy link
Member Author

Ah, I see. This is great. Thank you!

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/nuxt/src/imports/module.ts (1)

154-160: Use canonicalised names for conflict detection

After adopting nuxtImportNames, update the check to avoid missing conflicts.

-            if (nuxtImports.has(value) && (!i.priority || i.priority >= 0 /* default priority */)) {
+            if (nuxtImportNames.has(value) && (!i.priority || i.priority >= 0 /* default priority */)) {
🧹 Nitpick comments (2)
packages/nuxt/src/pages/module.ts (1)

431-436: Co-locate imports:sources hooks for readability

You already adjust router guard imports via imports:sources at Lines 309–314. Consider grouping these hooks together to make all import-source mutations discoverable in one place.

packages/nuxt/src/imports/module.ts (1)

14-21: Avoid cross-module initialisation side-effects; extract shared presets to a sidecar

Importing from ../pages/module executes that module’s top-level initialisation. To minimise coupling and evaluation cost, move pagesImportPresets/routeRulesPresets into a small shared file (e.g. ../imports/core-presets.ts) that exports only data, and import from there in both modules.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 097c591 and 647009e.

📒 Files selected for processing (2)
  • packages/nuxt/src/imports/module.ts (3 hunks)
  • packages/nuxt/src/pages/module.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/pages/module.ts
  • packages/nuxt/src/imports/module.ts
🧠 Learnings (3)
📓 Common learnings
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.
📚 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/module.ts
  • packages/nuxt/src/imports/module.ts
📚 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/imports/module.ts
🧬 Code graph analysis (1)
packages/nuxt/src/imports/module.ts (2)
packages/nuxt/src/pages/module.ts (2)
  • pagesImportPresets (29-32)
  • routeRulesPresets (34-36)
packages/nuxt/src/imports/presets.ts (1)
  • defaultPresets (277-283)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build
  • GitHub Check: code
🔇 Additional comments (4)
packages/nuxt/src/pages/module.ts (3)

23-23: LGTM: type-only import

Importing InlinePreset as a type keeps runtime lean. No issues.


29-32: Verify useLink isn’t already provided by default presets

If routerPreset (in imports/presets.ts) already exposes useLink, this introduces a duplicate preset entry. Unimport de-duplicates, but keeping a single source reduces noise.


34-36: LGTM: scoped preset for defineRouteRules

Exporting this as a preset is clean and keeps it composable with imports:sources.

packages/nuxt/src/imports/module.ts (1)

16-21: Double-check gating for routeRulesPresets

allNuxtPresets unconditionally includes routeRulesPresets, while actual registration of those presets is gated by inlineRouteRules. Your name-set below uses presets (post imports:sources) so behaviour should be gated correctly, but please verify no warning is emitted for defineRouteRules when inlineRouteRules is false.

Comment on lines 132 to 135
const isIgnored = createIsIgnored(nuxt)
const defaultImportSources = new Set(defaultPresets.flatMap(i => i.from))
const defaultImports = new Set(presets.flatMap(p => defaultImportSources.has(p.from) ? p.imports : []))
const nuxtImportSources = new Set(allNuxtPresets.flatMap(i => i.from))
const nuxtImports = new Set(presets.flatMap(p => nuxtImportSources.has(p.from) ? p.imports : []))
const regenerateImports = async () => {
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Normalise names and include per-import from to avoid false negatives

nuxtImports currently stores raw p.imports (strings, tuples, or objects). Later you .has(value: string), which won’t match tuples/objects. Also, some presets specify from per import; those sources should be included in the “Nuxt sources” set.

Apply the following diff and helper:

-    const nuxtImportSources = new Set(allNuxtPresets.flatMap(i => i.from))
-    const nuxtImports = new Set(presets.flatMap(p => nuxtImportSources.has(p.from) ? p.imports : []))
+    const nuxtImportSources = new Set(
+      allNuxtPresets
+        .flatMap(p => [
+          p.from,
+          ...p.imports.map(i => (typeof i === 'object' && !Array.isArray(i) && i?.from) ? i.from : undefined),
+        ])
+        .filter(Boolean) as string[],
+    )
+    const nuxtImportNames = new Set<string>(
+      presets.flatMap(p =>
+        p.imports
+          .map(i => {
+            const itemFrom = (typeof i === 'object' && !Array.isArray(i) && i?.from) ? i.from : p.from
+            return itemFrom && nuxtImportSources.has(itemFrom) ? normaliseImportName(i) : undefined
+          })
+          .filter(Boolean) as string[],
+      ),
+    )

Place this helper near the top of the file:

function normaliseImportName(i: unknown): string | undefined {
  if (typeof i === 'string') { return i }
  if (Array.isArray(i)) { return (i[1] as string | undefined) || (i[0] as string | undefined) }
  if (i && typeof i === 'object' && 'name' in (i as any)) {
    const o = i as { name?: string; as?: string }
    return o.as || o.name
  }
  return undefined
}
🤖 Prompt for AI Agents
In packages/nuxt/src/imports/module.ts around lines 132-135, nuxtImports is
built from raw p.imports which may be strings, tuples, or objects causing .has
checks to miss matches and also ignores per-import from overrides; add the
provided normaliseImportName helper near the top of the file, expand
nuxtImportSources to include any per-import `from` values found on individual
imports, and rebuild nuxtImports by normalising each import entry (using
normaliseImportName) to a string before adding to the Set so tuple/object
imports match string checks later.

@danielroe danielroe merged commit 56aa16c into nuxt:main Sep 5, 2025
46 of 47 checks passed
@github-actions github-actions bot mentioned this pull request Sep 5, 2025
danielroe pushed a commit that referenced this pull request Sep 5, 2025
@github-actions github-actions bot mentioned this pull request Sep 5, 2025
This was referenced Sep 5, 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.

3 participants