Skip to content

fix: reset variable render names between outputs in the same generate#6350

Merged
lukastaegert merged 2 commits into
rollup:masterfrom
barry3406:fix/multi-output-render-name-leak
Apr 18, 2026
Merged

fix: reset variable render names between outputs in the same generate#6350
lukastaegert merged 2 commits into
rollup:masterfrom
barry3406:fix/multi-output-render-name-leak

Conversation

@barry3406

Copy link
Copy Markdown
Contributor

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
  • no

List any relevant issue numbers:

Fixes #6296

Description:

When the same input bundle is generated for multiple outputs in a single output array, Variable.renderBaseName set during one output's import deconfliction was left on the shared Variable instance and leaked into the next output.

Concretely: generating a chunked CJS output calls deconflictImportsOther, which sets setRenderNames(chunk.variableName, exportName) on imported variables — so a function _ imported from a vendor chunk ends up with renderBaseName='vendor', renderName='_'. The state lives on the shared Variable instance, not on a per-output structure. When the next output (UMD) goes through deconflictTopLevelVariables, the !variable.renderBaseName skip leaves the stale vendor in place, and the local function declaration ends up rendered as function vendor._(...) — invalid JavaScript.

Fix: reset renderBaseName/renderName to null for top-level variables of the chunk's modules at the start of setIdentifierRenderResolutions, before either the exports loop or deconflictChunk reassigns them. Each output then starts from a clean slate.

Added a regression test in test/misc/misc.js that exercises the exact scenario from #6296: a single bundle generated as both chunked CJS (with a vendor manualChunk) and UMD, asserting the UMD output contains no dotted function declarations and is parseable as valid JavaScript.

When the same input bundle is generated for multiple outputs in one
`output` array, `Variable.renderBaseName` set during a chunked output's
import deconfliction (e.g. `vendor` for `_` imported from a chunk) was
left on the shared `Variable` instance. The next output's
`deconflictTopLevelVariables` then skipped that variable because of the
existing `renderBaseName`, so the function declaration was rendered as
`function vendor._(...)` — invalid JavaScript.

Reset `renderBaseName`/`renderName` for the chunk's top-level variables
at the start of `setIdentifierRenderResolutions`, before either the
exports loop or `deconflictChunk` reassigns them.
@vercel

vercel Bot commented Apr 11, 2026

Copy link
Copy Markdown

@barry3406 is attempting to deploy a commit to the rollup-js Team on Vercel.

A member of the Team first needs to authorize it.

@codecov

codecov Bot commented Apr 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.78%. Comparing base (1fa79d0) to head (1ace671).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6350   +/-   ##
=======================================
  Coverage   98.78%   98.78%           
=======================================
  Files         274      274           
  Lines       10788    10791    +3     
  Branches     2881     2881           
=======================================
+ Hits        10657    10660    +3     
  Misses         89       89           
  Partials       42       42           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lukastaegert lukastaegert left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry for missing this, this looks like a really nice fix. Will merge and release it once pipelines agree.

@vercel

vercel Bot commented Apr 18, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
rollup Ready Ready Preview, Comment Apr 18, 2026 4:50am

Request Review

@lukastaegert lukastaegert added this pull request to the merge queue Apr 18, 2026
Merged via the queue into rollup:master with commit 5e6fb9f Apr 18, 2026
47 checks passed
@github-actions

Copy link
Copy Markdown

This PR has been released as part of rollup@4.60.2. You can test it via npm install rollup.

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.

Invalid UMD output when mixed outputs include CJS manualChunks: generated code contains illegal syntax like function vendor.xxx()

2 participants