Skip to content

Conversation

@Flo0806
Copy link
Collaborator

@Flo0806 Flo0806 commented Oct 2, 2025

🔗 Linked issue

fix #33378

📚 Description

Fixes "Cannot redefine property: _path" error during HMR when CSS changes trigger middleware module reload.

Problem

When CSS files change, Vite-Node triggers HMR and reloads the middleware module. The _path property was defined without configurable: true, causing TypeErrors when the property was redefined in the same context.

Solution

Add configurable: true to both Object.defineProperty calls in the middleware template, allowing properties to be safely redefined during HMR.

@Flo0806 Flo0806 requested a review from danielroe as a code owner October 2, 2025 18:57
@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 2, 2025

Walkthrough

The change updates two Object.defineProperty invocations in packages/nuxt/src/core/templates.ts to include configurable: true for the _path property. This applies to the global middleware object and the dynamically wrapped named middleware. The control flow and structure remain the same, and no exported or public entity signatures were modified.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Linked Issues Check ⚠️ Warning The changes implement the required fix by adding the configurable: true flag to the middleware _path property, preventing the TypeError during CSS-triggered HMR, but the PR does not include automated tests to reproduce and verify the HMR edit flow as requested in the linked issue (#33378). Add automated tests that reproduce the CSS edit HMR scenario and verify that redefining _path no longer throws an error to fully satisfy the linked issue requirements.
✅ Passed checks (4 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly describes the primary change by stating that the middleware _path property is now configurable for HMR in Nuxt, and it concisely conveys the main focus of the fix without superfluous details.
Out of Scope Changes Check ✅ Passed All modifications are confined to updating the configurable flag on the _path property within the middleware template, and there are no unrelated or extraneous changes beyond the linked issue’s scope.
Description Check ✅ Passed The pull request description directly explains the HMR error and the solution of adding configurable: true to the property definitions, aligning clearly with the changes implemented and remaining fully on-topic.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 011c13e and 495334c.

📒 Files selected for processing (1)
  • packages/nuxt/src/core/templates.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/core/templates.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). (20)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, default, manifest-off, json, lts/-1)
  • GitHub Check: test-fixtures (windows-latest, built, webpack, default, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (windows-latest, built, vite, default, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (windows-latest, built, webpack, async, 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 (windows-latest, dev, vite, async, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (windows-latest, dev, vite, async, manifest-off, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, webpack, default, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (windows-latest, dev, vite, default, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, rspack, async, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, async, 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, dev, vite, async, manifest-off, json, lts/-1)
  • GitHub Check: release-pkg-pr-new
  • GitHub Check: test-size
  • GitHub Check: test-benchmark
  • GitHub Check: typecheck (windows-latest, bundler)
  • GitHub Check: typecheck (ubuntu-latest, bundler)
  • GitHub Check: code
🔇 Additional comments (2)
packages/nuxt/src/core/templates.ts (2)

348-348: Correct fix for HMR property redefinition.

Adding configurable: true allows the _path property to be safely redefined during Hot Module Replacement, preventing the TypeError "Cannot redefine property: _path" when CSS changes trigger module reloads.


359-359: Consistent application of configurable property.

The configurable: true addition mirrors the fix for global middleware, ensuring both global and named middleware support HMR property redefinition. This provides complete coverage for the issue across all middleware types.


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.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 2, 2025

Open in StackBlitz

@nuxt/kit

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

nuxt

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

@nuxt/rspack-builder

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

@nuxt/schema

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

@nuxt/vite-builder

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

@nuxt/webpack-builder

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

commit: 495334c

@codspeed-hq
Copy link

codspeed-hq bot commented Oct 2, 2025

CodSpeed Performance Report

Merging #33379 will not alter performance

Comparing Flo0806:fix/middleware-hmr-redefine-property (495334c) with main (011c13e)

Summary

✅ 10 untouched

@danielroe danielroe merged commit d6df732 into nuxt:main Oct 2, 2025
48 checks passed
@github-actions github-actions bot mentioned this pull request Oct 2, 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.

Nuxt 4 + tailwindcss + directus gettng error "500 Cannot redefine property: _path"

2 participants