Skip to content

fix(core): avoid chunk filename conflicts in multi-compiler builds - #1777

Merged
Timeless0911 merged 3 commits into
mainfrom
david/fix-multicompiler-chunk-filenames
Jul 22, 2026
Merged

Timeless0911 merged 3 commits into
mainfrom
david/fix-multicompiler-chunk-filenames

Conversation

@Timeless0911

@Timeless0911 Timeless0911 commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Multi-compiler builds can emit runtime and other initial chunks through output.filename, while async chunks use output.chunkFilename. Without a compiler-specific namespace, non-entry chunks can collide with chunks or entries emitted by another library config into the same directory.

  • Preserve entry filenames while suffixing every non-entry initial/runtime and async chunk in multi-compiler builds with ~<index>, starting from ~0.
  • Apply collision protection to the default filename and string output.filename.js templates. Filename functions remain user-owned, and explicit tools.rspack.output.filename/chunkFilename overrides remain authoritative.
  • Extract the default ESM runtime only for bundleless or multi-entry builds, preserving the bundled single-entry single-file expectation.
Build and output.filename.js Entry Runtime / other initial Async
Single compiler, omitted or string Keep the original template Keep the original template Infer from the original template
Multi-compiler, omitted or string (compiler i) Keep the original template Append ~i Infer from the template and append ~i
Function User-owned User-owned User-owned; Rslib does not infer or suffix chunkFilename

Related Links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings July 21, 2026 06:50

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: df40b7b04f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/src/config.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates @rslib/core’s Rspack output naming logic to prevent JS chunk filename collisions in multi-compiler builds by switching from index prefixing to index suffixing (e.g. shared~1.js), and adjusts runtime chunk extraction rules for ESM to preserve the single-entry single-file expectation.

Changes:

  • Update chunk naming for multi-compiler builds to suffix non-entry and async chunks from later compilers with ~<index>.
  • Adjust ESM runtimeChunk defaults to extract the runtime only for bundleless or multi-entry builds.
  • Update unit/integration tests and snapshots to match the new naming behavior.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/integration/shims/index.test.ts Updates expected CJS shim chunk filename pattern for the new ~<index> suffix scheme.
tests/integration/resolve/index.test.ts Stabilizes assertions by querying known entry outputs instead of relying on Object.values ordering.
tests/integration/output/index.test.ts Reworks output naming expectations to validate suffixing behavior and runtime chunk extraction behavior.
tests/integration/output/chunkFileName-multi/src/runtime2.js Adds fixture entry that triggers runtime/shared chunk behavior in multi-compiler scenarios.
tests/integration/output/chunkFileName-multi/src/runtime1.js Adds fixture entry that triggers runtime/shared chunk behavior in multi-compiler scenarios.
tests/integration/output/chunkFileName-multi/src/runtime-dep.cjs Adds a small CJS dependency fixture used by the runtime entry fixtures.
tests/integration/output/chunkFileName-multi/rslib4.config.ts Adds a 4-lib multi-compiler fixture config to validate runtime/initial chunk suffixing behavior.
tests/integration/externals/index.test.ts Updates snapshots and content assertions for renamed runtime/dependency chunk outputs.
tests/integration/asset/index.test.ts Updates expected runtime import path to the suffixed runtime chunk output.
packages/core/tests/config.test.ts Adds/updates unit tests for chunkFilename inference/suffixing and removes runtimeChunk helper tests.
packages/core/tests/snapshots/config.test.ts.snap Updates snapshots for new chunkFilename and runtimeChunk defaults across formats/compilers.
packages/core/src/config.ts Implements suffix-based chunk naming (including default initial chunk handling) and revises ESM runtimeChunk defaulting logic.
Comments suppressed due to low confidence (1)

packages/core/src/config.ts:984

  • In multi-compiler builds with a user-provided string output.filename, this branch only suffixes chunkFilename but leaves output.filename untouched. Since Rspack can emit runtime/other initial (non-entry) chunks via output.filename, later compilers can still collide on files like rslib-runtime.js when runtimeChunk is enabled (bundleless or multi-entry). Consider applying the same non-entry initial chunk suffixing to output.filename for multiCompilerIndex > 0 (while keeping entry chunks unchanged), even when output.filename is a string template.
  const finalConfig: RsbuildConfig = userJsFilename
    ? chunkFilename
    : mergeRsbuildConfig(chunkFilename, {
        output: {
          filename: {

@Timeless0911
Timeless0911 marked this pull request as draft July 21, 2026 07:41
@Timeless0911

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 38d2646551

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/src/config.ts Outdated
@Timeless0911

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 31a5e2fa33

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Timeless0911
Timeless0911 marked this pull request as ready for review July 21, 2026 09:17
@Timeless0911
Timeless0911 enabled auto-merge (squash) July 22, 2026 03:22
@Timeless0911
Timeless0911 merged commit 7d0efc8 into main Jul 22, 2026
11 checks passed
@Timeless0911
Timeless0911 deleted the david/fix-multicompiler-chunk-filenames branch July 22, 2026 03:34
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.

3 participants

Sponsor
SponsoredKunjungi sekarang
Promo