Skip to content

Styles aren't always included in dev mode #16181

Closed

Description

@jurajkapsz

Astro Info

Astro                    v6.1.2
Vite                     v7.3.1
Node                     v24.6.0
System                   Linux (x64)
Package Manager          pnpm
Output                   static
Adapter                  @astrojs/node (v10.0.4)
Integrations             @astrojs/mdx (v5.0.3)
                         build/info
                         build/images
                         build/cleanup
                         @astrojs/sitemap (v3.7.2)
                         gab-astro-compress (v0.1.2)

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

After upgrading an Astro v5 project to Astro v6, it happens that the .astro component styles aren't included in the dev mode output.

Use case:

  • I have .astro components, that contains some markup, script and style tag:
<h1>My Component</h1>

<script> // component script </script>

<style type="scss" is:global> /* component styles */</style>
  • The components are included in multiple pages (as part of mdx content), for example:
---
frontmatter...
---

import Photo from "@components/content/photo.astro";

Some paragraph...

<Photo ... />

Some paragraph...
  • When browsing the website in dev mode, the style of some components is most of the time missing, but not always; ie on certain pages the component has its styles included, on others it does not and the presentation is broken.
  • After running build, the styles are again present as they should, even in places, where they were missing in dev mode.

I was not able to reproduce this on a brand new Astro v6 install yet.

This issue appeared alongside #16179 issue (after upgrade to Astro v6).

What's the expected result?

All styles should be present in dev mode view the same way as later in the built version (or like in Astro v5).

Link to Minimal Reproducible Example

Participation

  • I am willing to submit a pull request for this issue.

Activity

  1. added
    triage: needs triage
    on Apr 1, 2026
  2. astrobot-houston commented on Apr 1, 2026

    @astrobot-houston
    Contributor

    I was unable to reproduce this issue. I created a triage project matching the reported setup — .astro components with <style type="scss" is:global> tags imported across multiple MDX pages, the @astrojs/node adapter, and output: 'static'. After extensive testing (sequential requests, concurrent stress tests, browser-based verification, and pages with 10+ styled components), all styles were consistently present in dev mode across all pages. This aligns with your own observation that you were unable to reproduce on a fresh Astro v6 install.

    I was unable to find a fix for this issue. Since the bug could not be reproduced in a clean environment, the root cause is likely tied to your specific project configuration. Some things to try: (1) delete node_modules/.vite/, .astro/, and node_modules/.cache/ to clear stale caches from the v5-to-v6 upgrade, (2) temporarily disable custom integrations (build/info, build/images, build/cleanup, gab-astro-compress) to see if one of them interferes with style collection, and (3) verify your SCSS preprocessor setup is compatible with Vite 7 / Astro v6. A minimal reproducible example would be essential for further investigation.

    P3: minor bug. This appears to be an edge case specific to a particular project configuration — likely related to the v5-to-v6 upgrade path combined with custom integrations and SCSS preprocessing. The reporter and automated triage both failed to reproduce on fresh installs, suggesting most users upgrading to Astro v6 will not encounter this issue.

    Full Triage Report

    Triage Report: Issue #16181 — Styles aren't always included in dev mode

    Issue Details

    Description

    After upgrading an Astro v5 project to Astro v6, the reporter observes that .astro component styles aren't consistently included in dev mode output. The issue is intermittent — on certain pages the component has its styles included, on others it does not.

    The components use the following pattern:

    <h1>My Component</h1>
    <script> // component script </script>
    <style type="scss" is:global> /* component styles */</style>

    These components are imported in multiple MDX pages. When browsing in dev mode, styles are sometimes missing, but after running build, styles are always present correctly.

    The reporter explicitly noted: "I was not able to reproduce this on a brand new Astro v6 install yet."

    Reporter's Environment

    • Astro v6.1.2
    • Vite v7.3.1
    • Node v24.6.0
    • Linux (x64)
    • pnpm
    • Output: static
    • Adapter: @astrojs/node (v10.0.4)
    • Integrations: @astrojs/mdx (v5.0.3), @astrojs/sitemap, plus custom integrations (build/info, build/images, build/cleanup, gab-astro-compress)

    Expected Behavior

    All styles should be present in dev mode, same as in the built version and same as in Astro v5.

    Reproduction Link

    No minimal reproducible example was provided. The reproduction link was # (empty).

    Reproduction Attempt

    Environment Used

    • Astro v6.1.2 (workspace version)
    • Node v24.14.0
    • Linux (x64)
    • pnpm
    • @astrojs/mdx (workspace version)
    • @astrojs/node (workspace version)

    Setup

    Created a triage project (triage/gh-16181) based on the with-mdx example, configured with:

    • @astrojs/mdx integration
    • @astrojs/node adapter (matching reporter's config)
    • output: 'static' (matching reporter's config)

    Created multiple .astro components (Photo.astro, Alert.astro, Heading.astro, plus 10 Widget*.astro components) that match the pattern described in the issue:

    • HTML markup
    • <script> tags
    • <style type="scss" is:global> tags (matching the exact attribute combination the reporter uses)

    Created multiple MDX pages (index, page2-5, many-widgets) that import these components, matching the pattern described.

    Also tested with a shared layout (BaseLayout.astro) wrapping all pages with its own <style is:global> tag.

    Tests Performed

    1. Basic dev server test (without type="scss"): All pages served correctly with all expected style tags present. Tested 5 sequential requests per page.

    2. Dev server test with type="scss" is:global: Same result — all styles consistently present on all pages.

    3. Dev server with @astrojs/node adapter: Same result — all styles present.

    4. Dev server with layout wrapping: All pages showed expected style count (component styles + layout style).

    5. Concurrent request stress test: 10 concurrent requests per page, repeated 5 times. No style tags ever missing.

    6. Many components test: Created a page importing 10 widget components. All 11 style tags (10 widgets + 1 layout) consistently present across 20 concurrent requests.

    7. Browser-based test (agent-browser): Verified styles are present in a real browser environment, not just via curl. Navigated through multiple pages. All styles present.

    8. Build verification: Build completed successfully with all styles inlined in the HTML output of all pages, confirming the build side works as expected.

    Result

    NOT REPRODUCED. The bug could not be reproduced in a clean Astro v6.1.2 setup, even with:

    • The same component pattern (<style type="scss" is:global>)
    • Multiple MDX pages importing the same components
    • The @astrojs/node adapter
    • Layouts wrapping MDX content
    • Concurrent requests
    • Large numbers of styled components

    This aligns with the reporter's own statement that they were unable to reproduce on a fresh install.

    Theories

    The issue may be related to:

    1. Project-specific caching or Vite state: The reporter's project upgraded from v5 to v6, which may have left stale cached artifacts (e.g., in node_modules/.vite/ or .astro/) that cause intermittent style resolution failures.
    2. Custom integrations: The reporter uses custom integrations (build/info, build/images, build/cleanup, gab-astro-compress) that may interfere with style collection or rendering.
    3. SCSS processing: The type="scss" attribute in the style tag typically requires an SCSS preprocessor. If the project has SCSS configured in a specific way, it might interact poorly with Vite's style handling in dev mode.
    4. Related issue Styles from standalone page templates leaking into other templates #16179: The reporter mentions this appeared alongside Styles from standalone page templates leaking into other templates #16179. That issue may provide additional context about what changed during the upgrade.
    5. Race condition specific to larger projects: The reporter's project is likely much larger than our minimal reproduction, and race conditions might only manifest under specific module graph conditions.

    Recommendation

    This issue lacks a minimal reproducible example, and the reporter themselves confirmed they couldn't reproduce on a fresh install. The bug may be specific to the reporter's project configuration (custom integrations, SCSS setup, or stale cache from v5→v6 upgrade). A minimal reproduction from the reporter would be needed to investigate further.

    This report was made by an LLM. Mistakes happen, check important info.

  3. matthewp commented on Apr 1, 2026

    @matthewp
    Contributor

    Can you try again with astro@6.1.3? We did have some styling fixes in that.

  4. self-assigned this
    on Apr 1, 2026
  5. added
    needs response
    on Apr 1, 2026
  6. astrobot-houston commented on Apr 1, 2026

    @astrobot-houston
    Contributor

    I was unable to reproduce this issue. I created a reproduction project on astro@6.1.3 matching the reported setup — multiple .astro components with <style type="scss" is:global> tags imported across 5 MDX pages, using the @astrojs/node adapter with output: 'static'. After extensive testing (sequential requests, concurrent burst tests with 5 parallel requests per page, and verifying all component-specific styles on every page), all styles were consistently present in dev mode. This aligns with the reporter's own observation that the issue could not be reproduced on a fresh Astro v6 install.

    I was unable to find a fix for this issue. Since the reporter is on astro@6.1.2, it's worth noting that astro@6.1.3 includes fix: stop CSS traversal at page boundaries (#16116) — a CSS-related fix that could be relevant. As @matthewp suggested, upgrading to astro@6.1.3 is the recommended first step. If the issue persists after upgrading, clearing stale caches (node_modules/.vite/, .astro/) from the v5→v6 migration and temporarily disabling custom integrations (build/info, build/images, build/cleanup, gab-astro-compress) would help narrow down the cause. A minimal reproducible example is essential for further investigation.

    P3: minor bug. This appears to be an edge case specific to a particular project configuration — likely related to the v5→v6 upgrade path combined with custom integrations and SCSS preprocessing. Neither the reporter nor automated triage could reproduce the issue on fresh installs, and a CSS fix was already shipped in v6.1.3 that may address it.

    Full Triage Report

    Triage Report: Issue #16181 — Styles aren't always included in dev mode

    Issue Details

    Description

    After upgrading an Astro v5 project to Astro v6, .astro component styles aren't consistently included in dev mode output. The issue is intermittent — styles appear on some pages but not others. After astro build, styles are always present correctly. The reporter noted they were unable to reproduce on a fresh Astro v6 install.

    Reporter's Environment

    • Astro v6.1.2, Vite v7.3.1, Node v24.6.0
    • Linux (x64), pnpm
    • Output: static, Adapter: @astrojs/node (v10.0.4)
    • Integrations: @astrojs/mdx (v5.0.3), @astrojs/sitemap, plus custom integrations (build/info, build/images, build/cleanup, gab-astro-compress)

    Reproduction Link

    No minimal reproducible example was provided.

    Reproduction Attempt

    Environment Used

    • Astro v6.1.3 (workspace version)
    • @astrojs/mdx (workspace version)
    • @astrojs/node (workspace version)
    • Linux (x64), pnpm

    Setup

    Created a triage project with:

    • @astrojs/mdx integration, @astrojs/node adapter, output: 'static'
    • 5 .astro components (Photo, Alert, Heading, Card, CodeBlock) each with <script> tags and <style type="scss" is:global> tags
    • 5 MDX pages importing various combinations of these components
    • A shared BaseLayout.astro layout with its own <style is:global>

    Tests Performed

    1. Sequential requests: All 5 pages tested with 10 sequential requests each. All style tags present on every request.
    2. Concurrent burst test: 5 parallel curl requests per page, all 5 pages. Style tag counts were identical across all requests (4-6 style tags per page depending on component count).
    3. Component-specific verification: Checked for component-specific CSS class names (.photo-component, .alert-component, etc.) in HTML output. All components had their styles present on every page where they were used.
    4. Build verification: Production build completed successfully with all styles present.

    Result

    NOT REPRODUCED. Styles were consistently present in dev mode across all test scenarios on astro@6.1.3.

    Relevant Changes in v6.1.3

    The following CSS-related fix was included in astro@6.1.3 (which the reporter hasn't tried yet):

    • fix: stop CSS traversal at page boundaries (#16116) — prevents CSS graph traversal from crossing page boundaries

    Recommendations

    1. The reporter should upgrade to astro@6.1.3 as suggested by @matthewp
    2. Clear stale caches from the v5→v6 migration (node_modules/.vite/, .astro/, node_modules/.cache/)
    3. Temporarily disable custom integrations to isolate whether one interferes with style collection
    4. If the issue persists, provide a minimal reproducible example for further investigation

    This report was made by an LLM. Mistakes happen, check important info.

  7. jurajkapsz commented on Apr 2, 2026

    @jurajkapsz
    ContributorAuthor

    Can you try again with astro@6.1.3? We did have some styling fixes in that.

    I have upgraded Astro to the latest v6.1.3 and this issue is still present. I have deleted .astro folder in project's root folder, as well as .vite and .astro folders under node_modules, but no change either.

    So basically, under dev mode, I have some components without styles .e.g. like so (I have added devtools inspector overlay to show the extra/default margins present etc; the style tag is not present in page code at all):

    Image

    and after build it is as it should be:

    Image

    Happens to another component too (a video component), but not others I believe. I have quite a few components like these though, each having their styles etc. collocated within the .astro component.

    The interesting thing is, that in the dev mode, the otherwise broken component (e.g. "Photo") is all fine in one page but not in others. A screenshot from another page in dev mode where it is fine:

    Image

    The only difference I can think of right now is, that the page content itself is from a different content collection, where the component appears fine and where not. The collections themselves are all of the same type (local mdx files), only maintained/defined separatelly.

  8. jurajkapsz commented on Apr 2, 2026

    @jurajkapsz
    ContributorAuthor

    My current astro info:

    Astro                    v6.1.3
    Vite                     v7.3.1
    Node                     v24.6.0
    System                   Linux (x64)
    Package Manager          pnpm
    Output                   static
    Adapter                  @astrojs/node (v10.0.4)
    Integrations             @astrojs/mdx (v5.0.3)
                             build/info
                             build/images
                             build/cleanup
                             @astrojs/sitemap (v3.7.2)
                             gab-astro-compress (v0.1.2)
    
  9. astrobot-houston commented on Apr 2, 2026

    @astrobot-houston
    Contributor

    I was unable to reproduce this issue. I created a triage project on astro@6.1.3 with 3 separate content collections (blog, docs, tutorials), 15+ .astro components each with <style type="scss" is:global> and <script> tags, 16 MDX pages across all collections importing shared components, @astrojs/node adapter with output: 'static', and a shared layout. After testing with sequential requests, concurrent bursts, cold-start module graph scenarios, and instrumenting the internal getStylesForURL() function with debug logging, all component styles were consistently present on every page in dev mode. The debug output confirmed that the ?astroPropagatedAssets transform correctly collected styles for each MDX entry regardless of which content collection it belonged to.

    I was unable to find a fix for this issue. The dev mode CSS collection for content entries works through two parallel paths: page-level CSS via collectCSSWithOrder() (which stops at propagation boundaries) and content entry CSS via getStylesForURL() → crawlGraph() (which collects styles from each MDX file's imports). Both paths were verified working correctly with instrumented debug logging. Note that the CSS fix in v6.1.3 (PR #16116 "stop CSS traversal at page boundaries") only modified the build mode CSS traversal in plugin-css.ts — it does not affect dev mode. Since neither you nor three independent automated triage attempts could reproduce this on a fresh install, the root cause is very likely tied to your specific project. Suggestions: (1) temporarily disable custom integrations (build/info, build/images, build/cleanup, gab-astro-compress) one at a time to see if one interferes with style collection, (2) try removing type="scss" from <style> tags to test with plain CSS, (3) check if path aliases (@components/...) resolve consistently across collections, and (4) a minimal reproducible example would be essential for further investigation.

    P3: minor bug. This appears to be an edge case specific to a particular project configuration — likely related to the v5-to-v6 upgrade path combined with custom integrations, SCSS preprocessing, or project-specific module resolution. The reporter and three independent automated triage attempts all failed to reproduce on fresh installs, suggesting most users will not encounter this issue.

    Full Triage Report

    Triage Report: Issue #16181 — Styles aren't always included in dev mode

    Issue Details

    Description

    After upgrading an Astro v5 project to Astro v6, .astro component styles aren't consistently included in dev mode output. The issue is intermittent — on certain pages the component has its styles included, on others it does not. The <style> tag is reportedly completely absent from the page code.

    The components use the following pattern:

    <h1>My Component</h1>
    <script> // component script </script>
    <style type="scss" is:global> /* component styles */</style>

    These components are imported in multiple MDX pages across different content collections. When browsing in dev mode, styles are sometimes missing, but after running build, styles are always present correctly.

    Key details from the reporter's latest comment:

    • The issue persists on astro@6.1.3 (not just 6.1.2)
    • Clearing .astro and .vite cache directories didn't help
    • A component (e.g. "Photo") works fine on one page but its styles are missing on other pages
    • The difference correlates with which content collection the page belongs to
    • The collections are all of the same type (local MDX files) but are defined/maintained separately

    Reporter's Environment

    • Astro v6.1.2 (later confirmed v6.1.3 still affected)
    • Vite v7.3.1, Node v24.6.0
    • Linux (x64), pnpm
    • Output: static, Adapter: @astrojs/node (v10.0.4)
    • Integrations: @astrojs/mdx (v5.0.3), @astrojs/sitemap, plus custom integrations (build/info, build/images, build/cleanup, gab-astro-compress)

    Reproduction Link

    No minimal reproducible example was provided.

    Related Issues

    Reproduction Attempt

    Environment Used

    • Astro v6.1.3 (workspace version)
    • @astrojs/mdx (workspace version)
    • @astrojs/node (workspace version)
    • Node v24.14.0, Linux (x64), pnpm

    Setup

    Created a triage project (triage/gh-16181) with:

    • @astrojs/mdx integration, @astrojs/node adapter, output: 'static'
    • 3 separate content collections (blog, docs, tutorials) using glob() loaders
    • 15+ .astro components (Photo, Video, Alert, Card, CodeBlock, Widget1-Widget10) each with <script> tags and <style type="scss" is:global> tags
    • 16 MDX pages across all 3 collections importing various component combinations
    • A shared BaseLayout.astro layout with its own <style is:global>
    • Dynamic [...slug].astro pages for each collection

    Tests Performed

    1. Build verification: Production build completed successfully with all styles present.

    2. Sequential dev server requests: All pages tested with multiple sequential requests. Style tag counts were consistent across all runs — each page had the expected number of component styles plus layout styles.

    3. Component-specific style verification: Verified that expected component-specific CSS selectors (.photo-component, .alert-component, etc.) were present for each page's imported components.

    4. Concurrent burst test: Multiple parallel requests per page — all pages showed identical style tag counts.

    5. Cold module graph test: Cleared caches, restarted dev server, requested all pages simultaneously before warmup. All styles present.

    6. Internal function instrumentation: Added debug logging to getStylesForURL() in vite-plugin-content-assets.ts to trace exactly which styles were collected for each content entry. Confirmed that for every MDX file, the function correctly discovered and collected all imported component styles via crawlGraph().

    Result

    NOT REPRODUCED. The bug could not be reproduced in a clean Astro v6.1.3 environment, even with extensive testing matching the reporter's configuration.

    Architecture Analysis: Dev Mode CSS Collection for Content Entries

    The dev mode CSS system for content entries operates through two parallel mechanisms:

    Path 1: Page-Level CSS (vite-plugin-css/index.ts)

    The collectCSSWithOrder() function walks the Vite module graph from the page's virtual module, collecting CSS as it descends. It stops at ?astroPropagatedAssets boundaries (content collection entries), ensuring content entry styles are handled separately.

    Path 2: Content Entry CSS (vite-plugin-content-assets.ts)

    When a content entry with ?astroPropagatedAssets is transformed:

    1. The MDX file is SSR-imported if not already loaded
    2. getStylesForURL() calls crawlGraph() to walk the module graph from the MDX file
    3. Styles from imported .astro components are collected and baked into the virtual module code at transform time
    4. At render time, the Content component (created with propagation: 'self') injects these styles into the page head via createHeadAndContent()

    Key Finding: PR #16116 Does Not Affect Dev Mode

    The CSS fix in v6.1.3 (PR #16116 "stop CSS traversal at page boundaries") only modified plugin-css.ts — the build mode CSS traversal. The dev mode equivalent uses collectCSSWithOrder() and crawlGraph(), which already had propagation boundary checks since PR #15167.

    Potential Root Causes for the Reporter's Issue

    1. Custom integrations interference: The reporter uses build/info, build/images, build/cleanup, gab-astro-compress — any of which could modify the module graph, hook into Vite's transform pipeline, or alter module resolution in ways that interfere with style collection.

    2. SCSS preprocessor interaction: The type="scss" attribute requires SCSS preprocessing. A project-specific SCSS configuration interacting with Vite 7's preprocessor pipeline could cause intermittent transform failures that prevent style modules from appearing in the module graph.

    3. Path alias resolution: The reporter uses @components/content/photo.astro path aliases. If these aliases resolve differently depending on the importer (content collection context), crawlGraph()'s isImportedBy() check could fail for some entries.

    4. Stale v5→v6 migration state: The project was upgraded from v5 to v6. Content collections in v5 used a different system. Even with cache clearing, there may be structural patterns from v5 (e.g., src/content/config.ts vs src/content.config.ts) that interact poorly with v6's content layer.

    5. Module graph completeness at transform time: The ?astroPropagatedAssets transform bakes styles at first transform. If for certain content entries the module graph is incomplete at that time (e.g., because the MDX file's imports haven't been fully resolved), styles would be permanently missing until the module is invalidated.

    Recommendation

    A minimal reproducible example is essential for further investigation. The reporter should:

    1. Disable custom integrations one at a time
    2. Test with plain CSS instead of type="scss"
    3. Test with relative imports instead of path aliases
    4. Check if the issue correlates with content collection directory structure

    This report was made by an LLM. Mistakes happen, check important info.

  10. jurajkapsz commented on Apr 2, 2026

    @jurajkapsz
    ContributorAuthor

    A followup on the bot suggestions:

    1. The build/info, build/images, build/cleanup integrations are astro:build hooks, not sure if they have any impact on dev mode.
    2. Similar the gab-astro-compress, but I disabled it before and also now, and no change.
    3. I tried to add another - this time plain CSS - style tag into the component; it changed nothing on the behavior, just added styles to where styles are already present, and did not appeared in cases where styles aren't included due to the issue. As if the style tags aren't taken into account; the question is due to what.
    4. "check if path aliases (@components/...) resolve consistently across collections" -- not sure how to check this. It worked in Astro v5.

    I will be thinking about a reproducible example, at this moment my idea is to just add more and more features to a clean install, but I imagine this might be quite time expensive to do. Still, in this state I am not sure if I can develop the production site in a confident manner, so I will be thinking about a solution for the reproducible example. Any ideas are welcome.

  11. matthewp commented on Apr 2, 2026

    @matthewp
    Contributor

    @jurajkapsz Thanks for the info! Sorry about this, I would suggest staying on Astro 5 for the time being. I will be working on this soon.

  12. added
    - P4: important
    feat: styling
    and removed
    needs response
    triage: needs triage
    on Apr 2, 2026
  13. 34 remaining items

  14. astrobot-houston commented on May 18, 2026

    @astrobot-houston
    Contributor
    • Reproduced: Yes — using johnnydecimal's reproduction. Scoped styles are completely dropped in both dev and build when <Content /> from render(entry) is passed through a <Fragment slot="X"> named slot.
    • Exploration: Yes — View branch
    • Unit Test: Yes — packages/astro/test/units/render/head-injection-app.test.ts (new test: propagates head from Content inside Fragment named slot (#16181))
    • Priority: P4: important. This affects any Astro v6 project using content collections with render() where <Content /> is passed through a named slot (<Fragment slot="X">). This is a common pattern for wrapper/layout components. Multiple users have confirmed across v6.1.2–v6.3.3. Workaround exists (use a default slot instead of a named slot), but requires restructuring templates.

    The root cause is in renderFragmentComponent in packages/astro/src/runtime/server/render/component.ts. When <Fragment slot="X"> wraps <Content />, the Fragment component defers evaluating its slot contents until render time. But the Content component (with propagation: 'self') needs to register as a propagator before bufferHeadContent() flushes the <head>. Since Fragment doesn't eagerly evaluate its slot (unlike AstroComponentInstance, which does), the Content component is created too late — after head content has already been flushed — and its styles are silently discarded. This is a regression introduced by PR #16239, which changed Fragment from eager (renderSlotToString) to lazy (renderSlot) slot evaluation to fix a streaming issue, inadvertently breaking style propagation.

    I found a potential fix for this issue. The fix makes renderFragmentComponent eagerly evaluate its default slot (slot?.(result)) before returning the RenderInstance, matching the eager pre-rendering that AstroComponentInstance already does for all Astro components. This ensures propagating components like Content register their styles before bufferHeadContent() runs, while still preserving the streaming-friendly rendering path. All 270 render unit tests, 10 content-collections-render tests, 38 CSS tests, and 8 streaming tests pass.

    Try this fix

    You can test this fix right now without waiting for a release:

    npm i https://pkg.pr.new/astro@6e80e22
    

    If this fixes your issue, please leave a comment letting us know (e.g. "confirmed, this fixes it"). We'll then open a pull request to get this merged.

    Full Triage Report

    Triage Report: Issue #16181 — Styles aren't always included in dev mode

    Issue Details

    Reproduction

    REPRODUCED ✅ on Astro v6.3.3 using johnnydecimal's minimal reproduction.

    The trigger requires all three of these together:

    1. An MDX file imports an .astro component with a scoped <style>.
    2. The slug page renders that MDX via render(entry) from astro:content.
    3. The slug page passes <Content /> to a wrapper via <Fragment slot="X"> / <slot name="X" />.

    Flip any one of these and the style reappears (use direct import, render without wrapper, or use a default <slot />).

    The data-astro-cid-* scoping attribute is applied to the DOM element, proving Astro's scoping system processed the component, but the corresponding <style> tag is completely absent from the page.

    Root Cause

    The bug is in renderFragmentComponent in packages/astro/src/runtime/server/render/component.ts (~line 417). This is a regression from PR #16239 (merged April 7, 2026), which changed Fragment from eager slot evaluation (renderSlotToString) to lazy evaluation (renderSlot) to fix a streaming issue (#13283).

    The timing problem:

    1. Wrapper's AstroComponentInstance constructor eagerly pre-renders its "content" slot
    2. Inside that slot, renderComponent(Fragment, ...) dispatches to renderFragmentComponent()
    3. renderFragmentComponent() returns a RenderInstance without calling Fragment's default slot function
    4. The Content component inside Fragment's slot is never created — no propagator is registered
    5. bufferHeadContent() runs and finds 0 propagators → no styles collected
    6. Later during rendering, Content is finally created, but its head (styles) is discarded because head flushing already happened

    The codebase explicitly documents this requirement: // prerender the slots eagerly to make collection entries propagate styles and scripts (instance.ts line 33) and // The slots are initialized eagerly for head propagation. (component.ts line 464). Fragment's lazy evaluation violates this.

    Fix Applied

    Changed renderFragmentComponent to eagerly evaluate its default slot (slot?.(result)) before returning the RenderInstance, using renderChild instead of the deferred renderSlot. This triggers component instantiation and propagator registration before bufferHeadContent() runs, while preserving the streaming-friendly architecture.

     function renderFragmentComponent(result: SSRResult, slots: ComponentSlots = {}): RenderInstance {
     	const slot = slots?.default;
    +	const preRendered = slot?.(result);
     	return {
     		render(destination) {
    -			if (slot == null) return;
    -			return renderSlot(result, slot).render(destination);
    +			if (preRendered == null) return;
    +			return renderChild(destination, preRendered);
     		},
     	};
     }

    Test Added

    packages/astro/test/units/render/head-injection-app.test.ts — new test 'propagates head from Content inside Fragment named slot (#16181)' that simulates the exact compiler-generated pattern (Wrapper → Fragment(slot="content") → Content with propagation:'self'). Confirmed: fails without the fix (0 style tags), passes with the fix (1 style tag).

    Regression Testing

    This report was made by an LLM. The analysis may be wrong, and the potential fix might not work, but is intended as a starting point for exploring the issue.

  15. removed
    triage: needs triage
    on May 18, 2026
  16. jurajkapsz commented on May 18, 2026

    @jurajkapsz
    ContributorAuthor

    npm i https://pkg.pr.new/astro@6e80e22

    I've tried out the fix that bot proposed, but it does not fix my use case. I still have to play around with Johnny's reproduction.

  17. matthewp commented on May 18, 2026

    @matthewp
    Contributor

    @johnnydecimal can you see if the preview release fixes your issue? Could be different.

  18. johnnydecimal commented on May 19, 2026

    @johnnydecimal

    🥳 It works for me. From Claude:

    The pkg.pr.new build fixes #16181. Confirmed with JDBlock.astro in MDX:

    • Page: /blog/0080-headers
    • Element rendered: <pre class="jd-block" data-astro-cid-6k2pfw3n>
    • Style emitted: <style>.jd-block[data-astro-cid-6k2pfw3n]{overflow-x:auto}</style> ✅

    On 6.3.1 the data-astro-cid attribute was already on the element but the matching <style> block never
    made it into the page. With astro@6.3.3 from pkg.pr.new/astro@6e80e22, the scoped style is now linked
    in.

  19. removed
    triage: fix pending
    on May 19, 2026
  20. johnnydecimal commented on May 19, 2026

    @johnnydecimal
  21. matthewp commented on May 21, 2026

    @matthewp
    Contributor

    Will be fixed by #16702

  22. jurajkapsz commented on May 26, 2026

    @jurajkapsz
    ContributorAuthor

    I just tested the v6.3.8, that should contain the mentioned fix, but the fix does not work for me. It looks like we have a different issue, mine vs what others reported. I can check things on my side again and let know. But for sure I don't use named slots, just the default <slot />.

  23. alphanull commented on May 28, 2026

    @alphanull

    Yeah, problem also not solved on my side. Only workaround right now for me is to inject all deps manually (for dev, builds are not affected).

  24. johnnydecimal commented on May 29, 2026

    @johnnydecimal

    6.4 fixed it for me.

  25. jurajkapsz commented on May 29, 2026

    @jurajkapsz
    ContributorAuthor

    6.4 fixed it for me.

    Awesome, I think it would, but your use case is slightly different than mine.

  26. jurajkapsz commented on Jun 24, 2026

    @jurajkapsz
    ContributorAuthor

    Astro v7 resolved the issue I had.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

- P4: importantfeat: stylingpkg: astro

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions