Skip to content

fix(core): preserve repeated stylesheet imports - #6250

Merged
miguel-heygen merged 2 commits into
heygen-com:mainfrom
AksharP5:css-import-order
Oct 25, 2026
Merged

miguel-heygen merged 2 commits into
heygen-com:mainfrom
AksharP5:css-import-order

Conversation

@AksharP5

@AksharP5 AksharP5 commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

What

Keep a composition's styles when several local CSS imports reference the same file. A linked sheet that imports shared.css for print and then screen currently loses the screen rules when bundled.

Why

The same 320 by 180 fixture was checked in Chrome with screen media. Its background is green in the authored page:

Output Computed background Visible result
Published 0.8.193 bundle rgba(0, 0, 0, 0) White
Main ab57d0ee1 bundle rgba(0, 0, 0, 0) White
This patch rgb(0, 128, 0) Green, matching the authored page

The input is @import "shared.css" print; followed by @import "shared.css" screen;. The shared sheet sets the background to green. Two parent sheets importing that dependency under different media conditions fail the same way.

Related work

Fixes #6249

#922/#923 added local import expansion and diamond deduplication. #4664 preserves conditions on stylesheet links. This corrects the recursive local import set. CSS import processing treats every occurrence as a separate stylesheet, so unconditional diamond imports also keep their cascade positions. Qualified imports and linked-font discovery in #5827 are outside this change.

Originally based on main 9aadc0b9b, whose compiler and parser trees match the measured ab57d0ee1 baseline. Current main b97de59c8 has no changes to this PR's files.

How

Track only stylesheets active in the current recursion chain, starting with the linked entry stylesheet. Stop actual cycles and expand each sibling import in place. The existing path checks, URL rebasing and media wrapping stay in the same path. Update the diamond regression to protect cascade order rather than deduplication. The docs also explain that repeated imports can increase bundle size.

Test plan

  • Four regression cases fail on main: direct and inherited media conditions, diamond cascade order, and a cycle back to the entry stylesheet. All pass with the fix.
  • 201 bundler and adjacent tests pass. The 196 bundler tests also pass on Bun 1.4.4.
  • Baseline workspace build, patched core build and core typecheck pass.
  • The published 0.8.193 package and main both reproduce the missing screen rule.
  • 32 browser samples cover screen and print media, direct/nested imports, cascade order and cycles.
  • Independent GPT-6.1 Sol xhigh review passed 201 tests, 24 additional browser comparisons, five adjacent controls and three mutation controls.
  • Lint, formatting, diff checks, comment checks and normal commit hooks pass.
  • Documentation updated.
  • Comments follow CONTRIBUTING.md.

No full video render was run. Mintlify is unavailable locally; no dependencies were installed.

@mintlify

mintlify Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit d5c14ef.

Approve preview

@miguel-heygen miguel-heygen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for this. The fix is in the right place: the shared "already inlined" set becomes the chain of sheets currently being expanded, so repeated imports keep their own media condition and cascade position, and cycles are still cut. Seeding the set with the linked sheet itself also fixes a small extra case: a sheet that imports itself used to be inlined into itself once, and now appears once.

I ran the tests against the head of this branch and against main. The four new or changed tests fail on main and pass here, and they go through bundleToSingleHtml with a real <link>, which is the path renders take. I also checked a few more shapes: the same file imported twice with the same condition (both copies kept, which matches CSS), a cycle that does not go through the linked sheet (a -> b -> a is cut at a), and a shared file reached through both url() and string imports from different folders (both copies get the same rebased url()).

One non-blocking note: bundle size now grows with the number of import paths rather than the number of files. A tokens file imported by twenty component sheets is inlined twenty times, and deep diamond graphs grow exponentially with depth. That is what the browser applies too, so I would keep the behavior. A short line in the docs paragraph could save someone a surprise.

Verdict: APPROVE
Reasoning: The fix is small and correct for media conditions, cascade order and cycles, the tests fail on main and pass here through the real bundling path, and CI is green.

@miguel-heygen miguel-heygen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for adding the docs line. The new head only adds that note to docs/packages/core.mdx, and it reads well next to the existing @import paragraph. Nothing else changed since my last review, and CI is green here.

Verdict: APPROVE
Reasoning: The only change since the approved head is the docs note I suggested, CI is green and the branch merges cleanly with main.

@miguel-heygen
miguel-heygen added this pull request to the merge queue Oct 25, 2026
@miguel-heygen
miguel-heygen removed this pull request from the merge queue due to a manual request Oct 25, 2026
@miguel-heygen
miguel-heygen added this pull request to the merge queue Oct 25, 2026
@miguel-heygen
miguel-heygen removed this pull request from the merge queue due to a manual request Oct 25, 2026
@miguel-heygen
miguel-heygen added this pull request to the merge queue Oct 25, 2026
Merged via the queue into heygen-com:main with commit d44f67a Oct 25, 2026
124 checks passed
@heygengenesis heygengenesis Bot mentioned this pull request Oct 25, 2026
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.

Bundling repeated CSS imports drops later media conditions

2 participants