Repository navigation
fix(vite): ensure server sourcemap-preserver plugin actually runs - #35680
Conversation
This comment has been minimized.
This comment has been minimized.
|
is this definitely the issue? the linked issue is using nuxt v3 but (if so, we'll keep this PR open to main, merge it in, and I'll cherry-pick it back) |
@nuxt/kit
@nuxt/nitro-server
nuxt
@nuxt/rspack-builder
@nuxt/schema
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
packages/vite/src/plugins/sourcemap-preserver.test.ts (2)
63-72: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueImprove the mock to prevent regressions in array merging.
Currently, the
nitromock uses an emptyrollupConfig, which masks thedefuarray merging bug present in the source code. If you fix the source code to append the plugin, you should consider adding a dummy plugin to this mock to ensure the test catches any future regressions where the array is accidentally overwritten rather than appended to.💡 Proposed update to the test mock
let buildBefore: (() => void) | undefined const nitro: NitroMock = { - options: { rollupConfig: {} }, + options: { rollupConfig: { plugins: [{ name: 'existing-plugin' } as any] } }, hooks: { hook (name: string, handler: () => void) { if (name === 'build:before') {🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/vite/src/plugins/sourcemap-preserver.test.ts` around lines 63 - 72, Update the nitro mock’s options.rollupConfig in the sourcemap preservation test to include a dummy existing plugin array, ensuring the test verifies the source logic appends the new plugin without overwriting existing entries. Keep the existing hooks and build:before capture behavior unchanged.
77-80: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueLocate the plugin safely.
If the
rollupConfigmock is updated to include an existing plugin (or if Nitro natively injects plugins before this hook), the new plugin might not be at index0. Use.find()instead of a hardcoded index to ensure the test remains robust.💡 Proposed update
- const nitroPlugin = nitro.options.rollupConfig.plugins?.[0] + const nitroPlugin = nitro.options.rollupConfig.plugins?.find(p => p && p.name === 'nuxt:sourcemap-import') expect(nitroPlugin).toBeDefined() if (!nitroPlugin) { return } expect(nitroPlugin.name).toBe('nuxt:sourcemap-import')🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/vite/src/plugins/sourcemap-preserver.test.ts` around lines 77 - 80, Update the plugin lookup in the sourcemap-preservation test to search nitro.options.rollupConfig.plugins with find() for the plugin named "nuxt:sourcemap-import" instead of assuming it is at index 0. Keep the defined assertion and subsequent name validation against the located plugin.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/vite/src/plugins/sourcemap-preserver.test.ts`:
- Around line 63-72: Update the nitro mock’s options.rollupConfig in the
sourcemap preservation test to include a dummy existing plugin array, ensuring
the test verifies the source logic appends the new plugin without overwriting
existing entries. Keep the existing hooks and build:before capture behavior
unchanged.
- Around line 77-80: Update the plugin lookup in the sourcemap-preservation test
to search nitro.options.rollupConfig.plugins with find() for the plugin named
"nuxt:sourcemap-import" instead of assuming it is at index 0. Keep the defined
assertion and subsequent name validation against the located plugin.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: eebb03a4-1457-41e4-b4ac-270c0487f5b4
📒 Files selected for processing (2)
packages/vite/src/plugins/sourcemap-preserver.test.tspackages/vite/src/plugins/sourcemap-preserver.ts
Merging this PR will improve performance by 10.38%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ⚡ | loadNuxt in the basic test fixture |
419.4 ms | 379.9 ms | +10.38% |
Tip
Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.
Comparing Mateleo:fix/24414-sourcemap-vlq-mappings (db9f786) with main (567bb93)
Footnotes
-
3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
|
@danielroe So yes I tested it against Nuxt 4.5 and Nuxt 5 with Nitro v3. |
2ae51c0 to
cf01236
Compare
|
I think I think the right fix for that piece would be to open a PR in nitro to backport the same fix to v2. (dropping that piece for now) |
…5680) Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Daniel Roe <[email protected]> (cherry picked from commit a781ae4)
…5680) Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Daniel Roe <[email protected]> (cherry picked from commit a781ae4)
…5680) Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Daniel Roe <[email protected]>
…5680) Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Daniel Roe <[email protected]>
🔗 Linked issue
Resolves #24414
📚 Description
Nitro strips all the line-to-line mapping data from production sourcemaps to save space, the issue is that too aggressive and nukes the entire mapping whenever the bundle includes any
node_modulescode, which Nuxt's SSR output always does.So
entry.mjs.maphas an empty mappings field, so--enable-source-mapscan't trace errors back to app.vue, it stops atentry.mjs.What I did is tell Nitro when
sourcemapMinify: falseit keeps the full mappings. The chainentry.mjs → server.mjs.map → app.vuethen resolves correctly.