Skip to content

Conversation

@2hu12
Copy link
Contributor

@2hu12 2hu12 commented Dec 28, 2025

What does this PR do?

How did you verify your code works?

Verified locally using the reproduction repository mentioned in the issue: https://github.com/david-arteaga/bun-bundler-splitting-bug. The fix was validated on a local bun-debug build.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 28, 2025

Walkthrough

The getJSChunkForHTML method in Chunk.zig was refined to require a candidate chunk to satisfy other.isEntryPoint() alongside matching entry_point_id, adding an additional filter for entry-point status when locating JavaScript chunks for HTML output.

Changes

Cohort / File(s) Summary
Chunk selection logic
src/bundler/Chunk.zig
Narrowed getJSChunkForHTML condition to require both matching entry_point_id and other.isEntryPoint() status when selecting the JavaScript chunk for HTML, addressing incorrect chunk references with code splitting enabled

Suggested reviewers

  • Jarred-Sumner
  • markovejnovic
  • taylordotfish

Pre-merge checks

✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fix entry point check' accurately reflects the main code change, which narrowed the getJSChunkForHTML condition to require the entry point check.
Description check ✅ Passed The PR description fully covers both required template sections: it clearly explains what the fix does and how it was verified with the repro repository.
Linked Issues check ✅ Passed The code change directly addresses issue #24344 by fixing the getJSChunkForHTML function to require entry point verification, ensuring index.html references the correct JS entrypoint instead of split-out chunks.
Out of Scope Changes check ✅ Passed All changes are confined to the getJSChunkForHTML function in src/bundler/Chunk.zig and are directly scoped to fixing the entry point check issue described in #24344.

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 6b5de25 and 93da558.

📒 Files selected for processing (1)
  • src/bundler/Chunk.zig
🧰 Additional context used
📓 Path-based instructions (2)
src/**/*.zig

📄 CodeRabbit inference engine (src/CLAUDE.md)

src/**/*.zig: Private fields in Zig are fully supported using the # prefix: struct { #foo: u32 };
Use decl literals in Zig for declaration initialization: const decl: Decl = .{ .binding = 0, .value = 0 };
Prefer @import at the bottom of the file (auto formatter will move them automatically)

Files:

  • src/bundler/Chunk.zig
**/*.zig

📄 CodeRabbit inference engine (CLAUDE.md)

In Zig code, be careful with allocators and use defer for cleanup

Files:

  • src/bundler/Chunk.zig
🧠 Learnings (1)
📓 Common learnings
Learnt from: RiskyMH
Repo: oven-sh/bun PR: 24719
File: docs/bundler/executables.mdx:527-560
Timestamp: 2025-11-14T16:07:01.064Z
Learning: In the Bun repository, certain bundler features like compile with code splitting (--compile --splitting) are CLI-only and not supported in the Bun.build() JavaScript API. Tests for CLI-only features use backend: "cli" flag (e.g., test/bundler/bundler_compile_splitting.test.ts). The CompileBuildConfig interface correctly restricts these with splitting?: never;. When documenting CLI-only bundler features, add a note clarifying they're not available via the programmatic API.
🔇 Additional comments (2)
src/bundler/Chunk.zig (2)

52-62: LGTM! Fix correctly filters for entry point status.

The addition of other.isEntryPoint() on line 56 properly addresses the issue where code-split common chunks (which share the same entry_point_id but are not actual entry points) could be incorrectly returned. This ensures the HTML file references the true JavaScript entry point rather than a split-out common chunk.


64-74: No changes needed. The getCSSChunkForHTML method correctly lacks the isEntryPoint() check because CSS chunks have a fundamentally different structure than JavaScript chunks. There is exactly one CSS chunk per entry_point_id (all with is_entry_point=false), whereas JavaScript can have multiple chunks with the same entry_point_id (some true, some false). The isEntryPoint() check is necessary for JavaScript to distinguish entry point chunks from code-split chunks, but applying it to CSS would incorrectly return null for all CSS chunks since CSS chunks are never entry points—they are synthetic chunks derived from JS entry points for stylesheet bundling.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Collaborator

@Jarred-Sumner Jarred-Sumner left a comment

Choose a reason for hiding this comment

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

Can you add a test that fails with the system version of Bun and passes in the debug build in this branch?

@2hu12
Copy link
Contributor Author

2hu12 commented Dec 30, 2025

Can you add a test that fails with the system version of Bun and passes in the debug build in this branch?

I'll give it a try!

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.

Bun js bundler references the incorrect JS entrypoint when code splitting is enabled

2 participants