Skip to content

Conversation

@danielroe
Copy link
Member

🔗 Linked issue

resolves #30267

📚 Description

while I've not been able to reproduce the exact issue, this should resolve the problem by ensuring we don't expose in-progress app component values until they are fully populated/resolved.

it still might be possible for there to be issues if app is accessed after the app:resolved hook, but I think that should not occur...

@danielroe danielroe self-assigned this Aug 18, 2025
@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 Aug 18, 2025

Walkthrough

The app resolution in packages/nuxt/src/core/app.ts now collects layouts, middleware, plugins and configs into local, explicitly typed accumulators rather than mutating app.* during traversal. Normalisation, de-duplication and the “add back unspecified plugins” logic operate on these local arrays/objects. After resolution the final middleware, plugins, configs and layouts are merged into the public NuxtApp via a single Object.assign(app, { middleware, plugins, configs, layouts }) before extension. A new test (packages/nuxt/test/app.test.ts) verifies resolveApp populates non-empty middleware, plugins and layouts when app writes are proxied. No public API changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent 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 b4a7525 and 3dae96a.

📒 Files selected for processing (1)
  • packages/nuxt/src/core/app.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/nuxt/src/core/app.ts
⏰ 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: codeql (actions)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/app-resolution

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

🧹 Nitpick comments (4)
packages/nuxt/src/core/app.ts (3)

217-220: Duplicate normalisation runs; consider consolidating to a single pass

You normalise/dedupe middleware and plugins once before assignment, and again after the hook. That’s extra work every resolve and can be surprising for future maintainers.

Options:

  • Keep the post-hook pass (based on app.* as suggested) and drop this pre-hook pass, or
  • Keep this pre-hook pass to provide fully-resolved values to 'app:resolve' and drop the post-hook pass.

Given the potential for 'app:resolve' to mutate arrays, keeping only the post-hook pass is cleaner, but either way avoid both.

For example, to drop the pre-hook pass:

-  middleware = uniqueBy(await resolvePaths(nuxt, [...middleware].reverse(), 'path'), 'name').reverse()
-  plugins = uniqueBy(await resolvePaths(nuxt, plugins, 'src'), 'src')

195-207: Plugin aggregation and normalisation approach is sound

Gathering from layered configs and templated files before normalisation is clear. Forced casting in normalizePlugin(plugin as NuxtPlugin) is a minor smell but acceptable here if upstream types are broad.

If you want to avoid the cast, consider narrowing config.plugins at the source or adding a small type guard for plugin-like objects.


210-215: Re-introducing unspecified plugins preserves user order

Iterating reversed and unshifting maintains original user-specified order at the front. One nit: the inner some(p => p.src === plugin.src) shadows the outer p. Rename for readability.

-    if (!plugins.some(p => p.src === plugin.src)) {
+    if (!plugins.some(existing => existing.src === plugin.src)) {
       plugins.unshift(plugin)
     }
packages/nuxt/test/app.test.ts (1)

269-301: Good guard against exposing partial app structures

The Proxy-based test effectively ensures that layouts/middleware/plugins are only set with non-empty values, validating the “assign once when resolved” contract.

Two optional improvements:

  • Track write counts per property to ensure exactly one assignment occurs for each of 'layouts', 'middleware', 'plugins' (stricter regression guard).
  • Add a companion test that mutates app.* in an 'app:resolve' hook (e.g. pushing a plugin) and asserts the mutation persists post-resolve. This would catch the overwrite issue flagged in core.

Example augmentation for write counts:

-    const app = new Proxy(_app, {
+    const writes: Record<string, number> = { layouts: 0, middleware: 0, plugins: 0 }
+    const app = new Proxy(_app, {
       get (target, p, receiver) {
         return Reflect.get(target, p, receiver)
       },
       set (target, p, newValue, receiver) {
         if (p === 'middleware' || p === 'plugins') {
           expect(newValue).not.toEqual([])
+          writes[p as string]!++
         }
         if (p === 'layouts') {
           expect(newValue).not.toEqual({})
+          writes[p as string]!++
         }
         return Reflect.set(target, p, newValue, receiver)
       },
     })
 
     await resolveApp(nuxt, app)
+    expect(writes).toEqual({ layouts: 1, middleware: 1, plugins: 1 })

If you’d like, I can draft the hook-mutation test as well.

📜 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 95d574a and b4a7525.

📒 Files selected for processing (2)
  • packages/nuxt/src/core/app.ts (4 hunks)
  • packages/nuxt/test/app.test.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)

Follow standard TypeScript conventions and best practices

Files:

  • packages/nuxt/src/core/app.ts
  • packages/nuxt/test/app.test.ts
**/*.{test,spec}.{ts,tsx,js,jsx}

📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)

Write unit tests for core functionality using vitest

Files:

  • packages/nuxt/test/app.test.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/core/app.ts
🧬 Code Graph Analysis (2)
packages/nuxt/src/core/app.ts (3)
packages/nuxt/src/core/utils/names.ts (1)
  • hasSuffix (16-18)
packages/nuxt/src/core/utils/index.ts (2)
  • hasSuffix (1-1)
  • uniqueBy (4-16)
packages/kit/src/resolve.ts (1)
  • findPath (68-86)
packages/nuxt/test/app.test.ts (2)
packages/nuxt/src/core/nuxt.ts (1)
  • loadNuxt (731-842)
packages/nuxt/src/core/app.ts (2)
  • createApp (14-22)
  • resolveApp (137-239)
🔇 Additional comments (4)
packages/nuxt/src/core/app.ts (4)

230-231: Single final assignment prevents exposing partial app state

Assigning layouts, middleware, plugins, and configs in one go avoids leaking partially populated values mid-resolution. This aligns with the PR intent and should reduce race-y consumers seeing transient empties.


160-172: Layout precedence relies on iteration order; sanity-check desired behaviour

Using layouts[name] ||= { name, file } means the first occurrence wins. Given you iterate layerConfigs (not reversed), confirm this preserves the desired precedence across layers for layouts (tests indicate it does). If the intended behaviour is “later layers override earlier ones”, be sure layerConfigs is ordered accordingly.


176-191: Middleware aggregation looks good

Collecting middleware across reversed layers and deferring normalisation until the end prevents partial writes and preserves override semantics via later de-duplication.


222-227: App config collection is straightforward

Collecting app.config paths per layer with findPath and deferring de-duplication makes sense in the new pattern.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Aug 18, 2025

Open in StackBlitz

@nuxt/kit

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

nuxt

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

@nuxt/rspack-builder

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

@nuxt/schema

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

@nuxt/vite-builder

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

@nuxt/webpack-builder

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

commit: 3dae96a

@codspeed-hq
Copy link

codspeed-hq bot commented Aug 18, 2025

CodSpeed Performance Report

Merging #32993 will not alter performance

Comparing fix/app-resolution (3dae96a) with main (2f58d4c)

Summary

✅ 10 untouched benchmarks

@danielroe danielroe merged commit e9cfb94 into main Aug 18, 2025
82 of 83 checks passed
@danielroe danielroe deleted the fix/app-resolution branch August 18, 2025 17:25
@github-actions github-actions bot mentioned this pull request Aug 18, 2025
@github-actions github-actions bot mentioned this pull request Sep 2, 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.

WARN 'manifest-route-rule' middleware already exists when copy paste some files (in that case pages)

2 participants