Skip to content

fix(inject): return a null sourcemap when nothing is injected - #2040

Open
onmax wants to merge 1 commit into
rollup:masterfrom
onmax:fix/inject-unchanged-sourcemap
Open

onmax wants to merge 1 commit into
rollup:masterfrom
onmax:fix/inject-unchanged-sourcemap

Conversation

@onmax

@onmax onmax commented Nov 6, 2026 •

Copy link
Copy Markdown

Rollup Plugin Name: inject

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

If yes, then include "BREAKING CHANGES:" in the first commit message body, followed by a description of what is breaking.

List any relevant issue numbers:

None.

Description

When inject matches one of its keys in a module but has nothing to inject, it still returns a hires sourcemap for the unchanged code. Rollup keeps that map on the cached module, so watch mode holds one for each of these modules. A 134 KB module that only calls options.process(...) gets a map with 131,780 segments.

I hit this in a Nuxt 4 dev server. Nitro 2 runs inject over every inlined dependency, and these maps took about 1.5 GB of heap per rebuild until the server ran out of memory.

This PR returns map: null when nothing is injected, like replace does. The output sourcemap stays byte-identical. The new test fails on master and passes here.

Repro with Rollup 4.67.5 and plugin 5.0.5, plus a patched control: https://github.com/onmax/repros/tree/repro/rollup-plugin-inject-sourcemap/rollup-plugin-inject-sourcemap (pnpm install && pnpm verify)

@onmax
onmax requested a review from shellscape as a code owner November 6, 2026 08:21
@greptile-apps

greptile-apps Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Reviews (1) · Last reviewed commit: "fix(inject): return a null sourcemap whe..." · Reviewed by Greptile

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant