fix(bake): preserve CSS import order in dev server#28119
fix(bake): preserve CSS import order in dev server#28119
Conversation
The dev server's incremental graph built import linked lists by prepending each edge (stack-style), which reversed the order relative to source. This caused CSS files imported from JS to appear in the wrong cascade order, making earlier imports override later ones. Reverse the linked list after construction so imports are traversed in source order, matching Bun.build behavior. Fixes #28117 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Updated 2:16 PM PT - Mar 14th, 2026
❌ Your commit 🧪 To try this PR locally: bunx bun-pr 28119That installs a local version of the PR into your bun-28119 --bun |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughFixes CSS import order preservation in the incremental graph by reversing newly constructed import edge lists to restore source order, ensuring consistent CSS cascade behavior during development. Changes
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 📝 Coding Plan
Comment |
|
Found 3 issues this PR may fix:
🤖 Generated with Claude Code |
There was a problem hiding this comment.
LGTM — straightforward linked list reversal to fix CSS cascade ordering, with a solid regression test.
Extended reasoning...
Overview
This PR fixes a CSS import order bug in the Bun dev server. The incremental graph builds import linked lists by prepending each edge (stack-style), which reversed the order relative to source code. The fix adds a standard in-place singly-linked list reversal after construction in processChunkDependencies, so that traceImports traverses CSS files in source order. Two files are changed: IncrementalGraph.zig (the fix) and css.test.ts (a regression test).
Security risks
None. This is a purely internal data structure ordering fix in the dev server bundler graph. No user input handling, authentication, or network-facing code is affected.
Level of scrutiny
Low-to-medium. The change is small (16 lines of Zig + 34 lines of test), self-contained, and uses a well-known algorithm. The old code even had a comment acknowledging the reversal issue but incorrectly claimed ordering did not matter. The defer on new_imports correctly captures the final reversed value since Zig defers evaluate at scope exit. The temporary .none assignment later in the function (to avoid tripping checkEdgeRemoval) is overwritten by the defer, preserving existing behavior.
Other factors
The reversal applies to all import types (both .normal and .css modes), which is harmless — source-order traversal is strictly more correct than reversed order. The test verifies cascade behavior (blue wins over red) both on initial load and after hard reload. The PR description confirms all 13 existing CSS dev server tests continue to pass.
Summary
Bun.servedev server, causing incorrect cascade behaviortraceImportstraversed these lists to collect CSS files, they appeared in reversed order, making earlier CSS imports override later onesprocessChunkDependenciesso imports are traversed in source order, matchingBun.buildbehaviorFixes #28117
Test plan
css import order is preserved (#28117)intest/bake/dev/css.test.tsfoo.css(color: red) thenbar.css(color: blue) and verifies blue wins the cascade viagetComputedStyleUSE_SYSTEM_BUN=1(receives "red") and passes with debug build (receives "#00f")🤖 Generated with Claude Code