Skip to content

fix(handler): skip CSS link tags for components without stylesheets#178

Merged
mohamedmansour merged 2 commits intomainfrom
chore/fix-link-css
Apr 6, 2026
Merged

fix(handler): skip CSS link tags for components without stylesheets#178
mohamedmansour merged 2 commits intomainfrom
chore/fix-link-css

Conversation

@mohamedmansour
Copy link
Copy Markdown
Contributor

The handler's head_end signal emitted tags for every component on the route, regardless of whether the component had a CSS file. Components like cb-page-group (no .css sibling) got phantom links that 404'd in the browser.

Root cause: the handler iterated needed_components and unconditionally wrote a tag using the component name as the href. No check for CSS existence.

Fix: add a css_href field to ComponentData in the protocol. The builder sets it only for Link-strategy components in Light DOM mode that have a CSS file. Shadow DOM components embed their own inside the shadow root template at parse time, so they don't need head links. Style and Module strategies never produce external CSS files.

The handler now emits tags only when css_href is non-empty, using the exact href from the protocol rather than constructing it from the component name.

Also consolidated three separate css_snapshot loops in the builder into a single pass with early-exit branches per strategy — Style strategy now does zero allocations in the CSS processing loop.

The handler's head_end signal emitted <link rel="stylesheet"> tags for
every component on the route, regardless of whether the component had a
CSS file. Components like cb-page-group (no .css sibling) got phantom
links that 404'd in the browser.

Root cause: the handler iterated needed_components and unconditionally
wrote a <link> tag using the component name as the href. No check for
CSS existence.

Fix: add a css_href field to ComponentData in the protocol. The builder
sets it only for Link-strategy components in Light DOM mode that have a
CSS file. Shadow DOM components embed their own <link> inside the shadow
root template at parse time, so they don't need head links. Style and
Module strategies never produce external CSS files.

The handler now emits <link> tags only when css_href is non-empty,
using the exact href from the protocol rather than constructing it from
the component name.

Also consolidated three separate css_snapshot loops in the builder into
a single pass with early-exit branches per strategy — Style strategy
now does zero allocations in the CSS processing loop.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@mohamedmansour mohamedmansour requested review from a team, akroshg and janechu April 6, 2026 19:53
@mohamedmansour mohamedmansour merged commit 5086216 into main Apr 6, 2026
21 checks passed
@mohamedmansour mohamedmansour deleted the chore/fix-link-css branch April 6, 2026 23:25
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