Skip to content

fix: evaluate banner/footer function addon per chunk - #1011

Merged
sxzz merged 1 commit into
rolldown:mainfrom
spokodev:fix/chunk-addon-per-chunk
Jul 11, 2026
Merged

sxzz merged 1 commit into
rolldown:mainfrom
spokodev:fix/chunk-addon-per-chunk

Conversation

@spokodev

@spokodev spokodev commented Jul 9, 2026

Copy link
Copy Markdown
Contributor
  • This PR contains AI-generated code, but I have carefully reviewed it myself. Otherwise, my PR may be closed.

Description

resolveChunkAddon returns an AddonFunction that Rolldown calls once per output chunk. When banner/footer is a function, the closure reassigned its own chunkAddon parameter with the first chunk's result:

if (typeof chunkAddon === 'function') {
  chunkAddon = chunkAddon({ format, fileName: chunk.fileName })
}

After the first chunk chunkAddon is no longer a function, so it is never invoked again — every later chunk reuses the first chunk's value. This was harmless when the context was only { format }, but once fileName was added to the context (and string returns were allowed) it means:

  • the fileName handed to the function is always the first chunk's name, and
  • a function returning a string produces the same string for every chunk.

Fix: compute a local resolved value on each invocation instead of overwriting the parameter.

Linked Issues

Additional context

Added a regression test that builds two entries with banner/footer functions echoing fileName. On main the second chunk gets the first chunk's banner/footer; with this fix each chunk gets its own.

The returned addon reassigned the `chunkAddon` parameter on its first
call, caching the first chunk's result for every subsequent chunk. As a
result the per-chunk `fileName` passed to the function was always the
first chunk's name, and function addons returning a string produced the
same output for all chunks.
@netlify

netlify Bot commented Jul 9, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for tsdown-main ready!

Name Link
🔨 Latest commit 3b9cacc
🔍 Latest deploy log https://app.netlify.com/projects/tsdown-main/deploys/6a4fb1b8faabe1000920298e
😎 Deploy Preview https://deploy-preview-1011--tsdown-main.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@pkg-pr-new

pkg-pr-new Bot commented Jul 9, 2026

Copy link
Copy Markdown

Open in StackBlitz

tsdown

pnpm add https://pkg.pr.new/tsdown@1011 -D
npm i https://pkg.pr.new/tsdown@1011 -D
yarn add https://pkg.pr.new/tsdown@1011.tgz -D

create-tsdown

pnpm add https://pkg.pr.new/create-tsdown@1011 -D
npm i https://pkg.pr.new/create-tsdown@1011 -D
yarn add https://pkg.pr.new/create-tsdown@1011.tgz -D

@tsdown/css

pnpm add https://pkg.pr.new/@tsdown/css@1011 -D
npm i https://pkg.pr.new/@tsdown/css@1011 -D
yarn add https://pkg.pr.new/@tsdown/css@1011.tgz -D

@tsdown/exe

pnpm add https://pkg.pr.new/@tsdown/exe@1011 -D
npm i https://pkg.pr.new/@tsdown/exe@1011 -D
yarn add https://pkg.pr.new/@tsdown/exe@1011.tgz -D

tsdown-migrate

pnpm add https://pkg.pr.new/tsdown-migrate@1011 -D
npm i https://pkg.pr.new/tsdown-migrate@1011 -D
yarn add https://pkg.pr.new/tsdown-migrate@1011.tgz -D

commit: 3b9cacc

@sxzz
sxzz merged commit 517c5f3 into rolldown:main Jul 11, 2026
16 checks passed
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.

2 participants