Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/nuxtPublic

refactor(nuxt): unitywindow.__NUXT__ structure#33867

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
typed-sigterm wants to merge1 commit intonuxt:main
base:main
Choose a base branch
Loading
fromtyped-sigterm:refactor/unity-nuxt-data-structure

Conversation

@typed-sigterm
Copy link
Contributor

🔗 Linked issue

#32486

📚 Description

@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz CodeflowRun & review this pull request inStackBlitz Codeflow.

@pkg-pr-new
Copy link

Open in StackBlitz

@nuxt/kit

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

@nuxt/nitro-server

npm i https://pkg.pr.new/@nuxt/nitro-server@33867

nuxt

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

@nuxt/rspack-builder

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

@nuxt/schema

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

@nuxt/vite-builder

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

@nuxt/webpack-builder

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

commit:160e940

@coderabbitai
Copy link

Walkthrough

The changes refactor payload handling and multi-app support across the Nuxt framework. The renderer utilities are updated to consistently wrap payloads under an appId key structure. Client-side payload retrieval is simplified by removing multiApp conditional logic and using a unified approach to access inline and external payloads. The entry point and app initialisation code are simplified by removing multiApp branching for SSR detection. The Window.NUXT type is narrowed to enforce a nested record structure, and config resolution is updated to use a fixed runtime path instead of conditional multiApp logic.

Possibly related PRs

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check nameStatusExplanationResolution
Docstring Coverage⚠️ WarningDocstring coverage is 33.33% which is insufficient. The required threshold is 80.00%.You can run@coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check nameStatusExplanation
Title check✅ PassedThe title 'refactor(nuxt): unitywindow.__NUXT__ structure' directly aligns with the main objective of unifying the window.NUXT structure across the codebase, as evidenced by the removal of multiApp branching and consolidation of payload handling patterns.
Description check✅ PassedThe description references linked issue#32486 but provides no substantive details about the changes. However, it is not completely unrelated to the changeset, as the linked issue likely provides context.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

✨ Issue Enrichment is now available for GitHub issues!

CodeRabbit can now help you manage issues more effectively:

  • Duplicate Detection — Identify similar or duplicate issues
  • Related Issues & PRs — Find relevant issues and PR's from your repository
  • Suggested Assignees — Find the best person to work on the issue
  • Implementation Planning — Generate detailed coding plans for engineers and agents
Disable automatic issue enrichment

To disable automatic issue enrichment, add the following to your.coderabbit.yaml:

issue_enrichment:auto_enrich:enabled:false

Thanks for usingCodeRabbit! 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

@coderabbitaicoderabbitaibot 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 between01d459e and160e940.

📒 Files selected for processing (6)
  • packages/nitro-server/src/runtime/utils/renderer/payload.ts (2 hunks)
  • packages/nuxt/src/app/composables/payload.ts (2 hunks)
  • packages/nuxt/src/app/entry.ts (2 hunks)
  • packages/nuxt/src/app/nuxt.ts (2 hunks)
  • packages/nuxt/src/app/types/augments.ts (1 hunks)
  • packages/nuxt/src/core/templates.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx,vue}

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

Follow standard TypeScript conventions and best practices

Files:

  • packages/nuxt/src/app/nuxt.ts
  • packages/nuxt/src/app/types/augments.ts
  • packages/nitro-server/src/runtime/utils/renderer/payload.ts
  • packages/nuxt/src/app/entry.ts
  • packages/nuxt/src/core/templates.ts
  • packages/nuxt/src/app/composables/payload.ts
**/*.{ts,tsx,js,jsx,vue}

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

**/*.{ts,tsx,js,jsx,vue}: Use clear, descriptive variable and function names
Add comments only to explain complex logic or non-obvious implementations
Keep functions focused and manageable (generally under 50 lines), and extract complex logic into separate domain-specific files
Remove code that is not used or needed
Use error handling patterns consistently

Files:

  • packages/nuxt/src/app/nuxt.ts
  • packages/nuxt/src/app/types/augments.ts
  • packages/nitro-server/src/runtime/utils/renderer/payload.ts
  • packages/nuxt/src/app/entry.ts
  • packages/nuxt/src/core/templates.ts
  • packages/nuxt/src/app/composables/payload.ts
🧠 Learnings (5)
📓 Common learnings
Learnt from: GalacticHypernovaRepo: nuxt/nuxt PR: 26468File: packages/nuxt/src/components/plugins/loader.ts:24-24Timestamp: 2024-11-05T15:22:54.759ZLearning: 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: GalacticHypernovaRepo: nuxt/nuxt PR: 26468File: packages/nuxt/src/components/plugins/loader.ts:24-24Timestamp: 2024-11-05T15:22:54.759ZLearning: 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/app/nuxt.ts
  • packages/nuxt/src/app/entry.ts
  • packages/nuxt/src/core/templates.ts
📚 Learning: 2024-12-12T12:36:34.871Z
Learnt from: huang-julienRepo: nuxt/nuxt PR: 29366File: packages/nuxt/src/app/components/nuxt-root.vue:16-19Timestamp: 2024-12-12T12:36:34.871ZLearning: 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:```jsconst 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/app/nuxt.ts
  • packages/nuxt/src/app/entry.ts
  • packages/nuxt/src/core/templates.ts
  • packages/nuxt/src/app/composables/payload.ts
📚 Learning: 2025-11-25T11:42:16.132Z
Learnt from: CRRepo: nuxt/nuxt PR: 0File: .github/copilot-instructions.md:0-0Timestamp: 2025-11-25T11:42:16.132ZLearning: Applies to **/*.vue : Use `<script setup lang="ts">` and the composition API when creating Vue components

Applied to files:

  • packages/nuxt/src/app/entry.ts
📚 Learning: 2025-11-25T11:42:16.132Z
Learnt from: CRRepo: nuxt/nuxt PR: 0File: .github/copilot-instructions.md:0-0Timestamp: 2025-11-25T11:42:16.132ZLearning: Applies to **/*.{ts,tsx,vue} : Follow standard TypeScript conventions and best practices

Applied to files:

  • packages/nuxt/src/app/entry.ts
🧬 Code graph analysis (2)
packages/nitro-server/src/runtime/utils/renderer/payload.ts (1)
packages/nuxt/src/app/nuxt.ts (1)
  • NuxtSSRContext (61-86)
packages/nuxt/src/app/composables/payload.ts (4)
test/utils.ts (1)
  • parsePayload (92-94)
packages/nuxt/src/app/nuxt.ts (1)
  • NuxtPayload (88-99)
packages/nuxt/src/app/index.ts (1)
  • NuxtPayload (4-4)
packages/nitro-server/src/runtime/utils/cache.ts (1)
  • payloadCache (7-7)
🔇 Additional comments (8)
packages/nuxt/src/app/nuxt.ts (2)

26-26:LGTM!

The import simplification correctly removes themultiApp flag that's no longer needed with the unified payload structure.


337-354:LGTM!

The client-side payload access is now consistently usingnuxtApp._id to key intowindow.__NUXT__, aligning with the unified structure. This simplifies the logic by removing the previous multiApp conditional branching.

packages/nuxt/src/app/types/augments.ts (1)

29-32:Type narrowing may affect external consumers.

This type change removes the looserRecord<string, any> branch from the union. While this correctly reflects the new unified structure, any third-party code or plugins that accessedwindow.__NUXT__ properties directly (without the appId key) may now encounter type errors.

Consider whether this warrants a mention in migration notes or release changelog, as external consumers may need to update their code to accesswindow.__NUXT__[appId] instead ofwindow.__NUXT__ directly.

packages/nuxt/src/app/entry.ts (1)

60-65:LGTM!

The SSR detection logic is well-structured:

  1. The fallback chain (data-nuxt-data attribute →__NUXT_DATA__ id) provides backwards compatibility.
  2. TheisSSR check correctly prioritises the payload'sserverRendered flag before falling back to the DOM element'sdata-ssr attribute.
packages/nuxt/src/app/composables/payload.ts (1)

121-137:LGTM with a note on merge precedence.

The refactored payload composition correctly:

  1. Uses the same element selection pattern asentry.ts for consistency.
  2. Separates inline and external payload sources with appId-scoped extraction.
  3. Guards against missing data with the early return.

The merge order (inlineAppDataexternalDatawindow.__NUXT__[appId]) means runtime-set values onwindow.__NUXT__ will override both inline and external payloads, which appears intentional for supporting dynamic updates.

packages/nitro-server/src/runtime/utils/renderer/payload.ts (3)

13-26:LGTM!

The payload response correctly wraps the payload under theappId key, and both JSON and module export formats consistently use this wrapped structure.


28-50:LGTM!

The JSON script rendering properly:

  1. Wraps payload data underappId.
  2. Maintains backwards compatibility by only settingid="__NUXT_DATA__" when not in multiApp mode.
  3. UsesObject.assign to merge config into the existing appId object, preserving any previously set data.

52-69:LGTM!

The script rendering correctly:

  1. Combines data and config intoappPayload before serialisation.
  2. Uses spread syntax in extraction mode to safely merge potentially undefined imported payloads.
  3. Consistently assigns towindow.__NUXT__[appId] in both extraction and non-extraction paths.

Comment on lines 374 to 379
return[
'export const useRuntimeConfig = () => ',
(!nuxt.options.future.multiApp
?'window?.__NUXT__?.config || window?.useNuxtApp?.().payload?.config'
:`window?.__NUXT__?.[${appId}]?.config || window?.useNuxtApp?.(${appId}).payload?.config`)
`window?.__NUXT__?.[${appId}]?.config || window?.useNuxtApp?.(${appId}).payload?.config`
||{},
].join('\n')
},

Choose a reason for hiding this comment

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

⚠️ Potential issue |🔴 Critical

Syntax error in template string construction.

The string concatenation appears malformed. Line 376 doesn't properly close the string before the|| {} fallback on line 377, which would result in|| {} being evaluated at template generation time rather than at runtime.

Apply this diff to fix the string construction:

 export const clientConfigTemplate: NuxtTemplate = {   filename: 'nitro.client.mjs',   getContents: ({ nuxt }) => {     const appId = JSON.stringify(nuxt.options.appId)     return [       'export const useRuntimeConfig = () => ',-      `window?.__NUXT__?.[${appId}]?.config || window?.useNuxtApp?.(${appId}).payload?.config`-        || {},+      `window?.__NUXT__?.[${appId}]?.config || window?.useNuxtApp?.(${appId}).payload?.config || {}`,     ].join('\n')   }, }
📝 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.

Suggested change
return[
'export const useRuntimeConfig = () => ',
(!nuxt.options.future.multiApp
?'window?.__NUXT__?.config || window?.useNuxtApp?.().payload?.config'
:`window?.__NUXT__?.[${appId}]?.config || window?.useNuxtApp?.(${appId}).payload?.config`)
`window?.__NUXT__?.[${appId}]?.config || window?.useNuxtApp?.(${appId}).payload?.config`
||{},
].join('\n')
},
return[
'export const useRuntimeConfig = () => ',
`window?.__NUXT__?.[${appId}]?.config || window?.useNuxtApp?.(${appId}).payload?.config || {}`,
].join('\n')
},
🤖 Prompt for AI Agents
In packages/nuxt/src/core/templates.ts around lines 374 to 379, the templatestring building the exported useRuntimeConfig function is malformed so the "||{}" fallback is evaluated at generation time instead of inside the generatedcode; fix it by ensuring the entire runtime expression (including the || {}) ispart of the returned string — close the template literal around the window/useNuxtApp expression and include the || {} inside that string (or build thefinal string via concatenation) so the fallback executes at runtime.

@codspeed-hq
Copy link

CodSpeed Performance Report

Merging#33867 willimprove performances by 11.4%

Comparingtyped-sigterm:refactor/unity-nuxt-data-structure (160e940) withmain (01d459e)

Summary

⚡ 1 improvement
✅ 9 untouched

Benchmarks breakdown

BenchmarkBASEHEADChange
writeTypes in the basic-types fixture93.9 ms84.3 ms+11.4%

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@coderabbitaicoderabbitai[bot]coderabbitai[bot] left review comments

@danielroedanielroeAwaiting requested review from danielroedanielroe is a code owner

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

@typed-sigterm

[8]ページ先頭

©2009-2025 Movatter.jp