Repository navigation
Closed
Labels
- P4: importantViolate documented behavior or significantly impacts performance (priority)feat: stylingRelated to styles (scope)pkg: astroRelated to the core `astro` package (scope)
Description
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
.astrocomponents, that contains some markup,scriptandstyletag:
<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
devmode, thestyleof 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 indevmode.
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.
Reacted by Alexander Wörndl and Eric Mika
Metadata
Metadata
Assignees
Labels
- P4: importantViolate documented behavior or significantly impacts performance (priority)feat: stylingRelated to styles (scope)pkg: astroRelated to the core `astro` package (scope)
Activity
astrobot-houston commentedon Apr 1, 2026
I was unable to reproduce this issue. I created a triage project matching the reported setup —
.astrocomponents with<style type="scss" is:global>tags imported across multiple MDX pages, the@astrojs/nodeadapter, andoutput: '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/, andnode_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
.astrocomponent 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:
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
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
Setup
Created a triage project (
triage/gh-16181) based on thewith-mdxexample, configured with:@astrojs/mdxintegration@astrojs/nodeadapter (matching reporter's config)output: 'static'(matching reporter's config)Created multiple
.astrocomponents (Photo.astro,Alert.astro,Heading.astro, plus 10Widget*.astrocomponents) that match the pattern described in the issue:<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
Basic dev server test (without
type="scss"): All pages served correctly with all expected style tags present. Tested 5 sequential requests per page.Dev server test with
type="scss" is:global: Same result — all styles consistently present on all pages.Dev server with
@astrojs/nodeadapter: Same result — all styles present.Dev server with layout wrapping: All pages showed expected style count (component styles + layout style).
Concurrent request stress test: 10 concurrent requests per page, repeated 5 times. No style tags ever missing.
Many components test: Created a page importing 10 widget components. All 11 style tags (10 widgets + 1 layout) consistently present across 20 concurrent requests.
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.
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:
<style type="scss" is:global>)@astrojs/nodeadapterThis aligns with the reporter's own statement that they were unable to reproduce on a fresh install.
Theories
The issue may be related to:
node_modules/.vite/or.astro/) that cause intermittent style resolution failures.build/info,build/images,build/cleanup,gab-astro-compress) that may interfere with style collection or rendering.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.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.
matthewp commentedon Apr 1, 2026
Can you try again with
astro@6.1.3? We did have some styling fixes in that.astrobot-houston commentedon Apr 1, 2026
I was unable to reproduce this issue. I created a reproduction project on
astro@6.1.3matching the reported setup — multiple.astrocomponents with<style type="scss" is:global>tags imported across 5 MDX pages, using the@astrojs/nodeadapter withoutput: '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 thatastro@6.1.3includesfix: stop CSS traversal at page boundaries (#16116)— a CSS-related fix that could be relevant. As @matthewp suggested, upgrading toastro@6.1.3is 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,
.astrocomponent styles aren't consistently included in dev mode output. The issue is intermittent — styles appear on some pages but not others. Afterastro build, styles are always present correctly. The reporter noted they were unable to reproduce on a fresh Astro v6 install.Reporter's Environment
Reproduction Link
No minimal reproducible example was provided.
Reproduction Attempt
Environment Used
Setup
Created a triage project with:
@astrojs/mdxintegration,@astrojs/nodeadapter,output: 'static'.astrocomponents (Photo,Alert,Heading,Card,CodeBlock) each with<script>tags and<style type="scss" is:global>tagsBaseLayout.astrolayout with its own<style is:global>Tests Performed
.photo-component,.alert-component, etc.) in HTML output. All components had their styles present on every page where they were used.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 boundariesRecommendations
astro@6.1.3as suggested by @matthewpnode_modules/.vite/,.astro/,node_modules/.cache/)This report was made by an LLM. Mistakes happen, check important info.
jurajkapsz commentedon Apr 2, 2026
I have upgraded Astro to the latest
v6.1.3and this issue is still present. I have deleted.astrofolder in project's root folder, as well as.viteand.astrofolders undernode_modules, but no change either.So basically, under
devmode, I have some components without styles .e.g. like so (I have added devtools inspector overlay to show the extra/default margins present etc; thestyletag is not present in page code at all):and after build it is as it should be:
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
.astrocomponent.The interesting thing is, that in the
devmode, the otherwise broken component (e.g. "Photo") is all fine in one page but not in others. A screenshot from another page indevmode where it is fine: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.
jurajkapsz commentedon Apr 2, 2026
My current astro info:
astrobot-houston commentedon Apr 2, 2026
I was unable to reproduce this issue. I created a triage project on
astro@6.1.3with 3 separate content collections (blog, docs, tutorials), 15+.astrocomponents each with<style type="scss" is:global>and<script>tags, 16 MDX pages across all collections importing shared components,@astrojs/nodeadapter withoutput: 'static', and a shared layout. After testing with sequential requests, concurrent bursts, cold-start module graph scenarios, and instrumenting the internalgetStylesForURL()function with debug logging, all component styles were consistently present on every page in dev mode. The debug output confirmed that the?astroPropagatedAssetstransform 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 viagetStylesForURL()→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 inplugin-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 removingtype="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,
.astrocomponent 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:
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:
astro@6.1.3(not just 6.1.2).astroand.vitecache directories didn't helpReporter's Environment
Reproduction Link
No minimal reproducible example was provided.
Related Issues
Reproduction Attempt
Environment Used
Setup
Created a triage project (
triage/gh-16181) with:@astrojs/mdxintegration,@astrojs/nodeadapter,output: 'static'blog,docs,tutorials) usingglob()loaders.astrocomponents (Photo,Video,Alert,Card,CodeBlock,Widget1-Widget10) each with<script>tags and<style type="scss" is:global>tagsBaseLayout.astrolayout with its own<style is:global>[...slug].astropages for each collectionTests Performed
Build verification: Production build completed successfully with all styles present.
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.
Component-specific style verification: Verified that expected component-specific CSS selectors (
.photo-component,.alert-component, etc.) were present for each page's imported components.Concurrent burst test: Multiple parallel requests per page — all pages showed identical style tag counts.
Cold module graph test: Cleared caches, restarted dev server, requested all pages simultaneously before warmup. All styles present.
Internal function instrumentation: Added debug logging to
getStylesForURL()invite-plugin-content-assets.tsto 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 viacrawlGraph().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?astroPropagatedAssetsboundaries (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
?astroPropagatedAssetsis transformed:getStylesForURL()callscrawlGraph()to walk the module graph from the MDX file.astrocomponents are collected and baked into the virtual module code at transform timeContentcomponent (created withpropagation: 'self') injects these styles into the page head viacreateHeadAndContent()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 usescollectCSSWithOrder()andcrawlGraph(), which already had propagation boundary checks since PR #15167.Potential Root Causes for the Reporter's Issue
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.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.Path alias resolution: The reporter uses
@components/content/photo.astropath aliases. If these aliases resolve differently depending on the importer (content collection context),crawlGraph()'sisImportedBy()check could fail for some entries.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.tsvssrc/content.config.ts) that interact poorly with v6's content layer.Module graph completeness at transform time: The
?astroPropagatedAssetstransform 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:
type="scss"This report was made by an LLM. Mistakes happen, check important info.
jurajkapsz commentedon Apr 2, 2026
A followup on the bot suggestions:
build/info,build/images,build/cleanupintegrations areastro:buildhooks, not sure if they have any impact ondevmode.gab-astro-compress, but I disabled it before and also now, and no change.styletag 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 thestyletags aren't taken into account; the question is due to what.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.
matthewp commentedon Apr 2, 2026
@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.
34 remaining items
astrobot-houston commentedon May 18, 2026
<Content />fromrender(entry)is passed through a<Fragment slot="X">named slot.packages/astro/test/units/render/head-injection-app.test.ts(new test:propagates head from Content inside Fragment named slot (#16181))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
renderFragmentComponentinpackages/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 (withpropagation: 'self') needs to register as a propagator beforebufferHeadContent()flushes the<head>. Since Fragment doesn't eagerly evaluate its slot (unlikeAstroComponentInstance, 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
renderFragmentComponenteagerly evaluate its default slot (slot?.(result)) before returning theRenderInstance, matching the eager pre-rendering thatAstroComponentInstancealready does for all Astro components. This ensures propagating components like Content register their styles beforebufferHeadContent()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:
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:
.astrocomponent with a scoped<style>.render(entry)fromastro:content.<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
renderFragmentComponentinpackages/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:
AstroComponentInstanceconstructor eagerly pre-renders its"content"slotrenderComponent(Fragment, ...)dispatches torenderFragmentComponent()renderFragmentComponent()returns aRenderInstancewithout calling Fragment's default slot functionbufferHeadContent()runs and finds 0 propagators → no styles collectedhead(styles) is discarded because head flushing already happenedThe 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
renderFragmentComponentto eagerly evaluate its default slot (slot?.(result)) before returning theRenderInstance, usingrenderChildinstead of the deferredrenderSlot. This triggers component instantiation and propagator registration beforebufferHeadContent()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.
jurajkapsz commentedon May 18, 2026
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.
matthewp commentedon May 18, 2026
@johnnydecimal can you see if the preview release fixes your issue? Could be different.
johnnydecimal commentedon May 19, 2026
🥳 It works for me. From Claude:
The pkg.pr.new build fixes #16181. Confirmed with
JDBlock.astroin MDX:/blog/0080-headers<pre class="jd-block" data-astro-cid-6k2pfw3n><style>.jd-block[data-astro-cid-6k2pfw3n]{overflow-x:auto}</style>✅On 6.3.1 the
data-astro-cidattribute was already on the element but the matching<style>block nevermade it into the page. With
astro@6.3.3frompkg.pr.new/astro@6e80e22, the scoped style is now linkedin.
johnnydecimal commentedon May 19, 2026
Workflow failed FYI. https://github.com/withastro/astro/actions/runs/26071134820
matthewp commentedon May 21, 2026
Will be fixed by #16702
fix(render): propagate styles through Fragment named slots (#16181) (#…
jurajkapsz commentedon May 26, 2026
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 />.alphanull commentedon May 28, 2026
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).
johnnydecimal commentedon May 29, 2026
6.4 fixed it for me.
jurajkapsz commentedon May 29, 2026
Awesome, I think it would, but your use case is slightly different than mine.
jurajkapsz commentedon Jun 24, 2026
Astro
v7resolved the issue I had.