You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unable to load UnoCSS style after updating astro from 6.0.8 to 6.1.3 #16204
Open two links in two browser windows. These two links are the same example but with different Astro versions (6.0.8 and 6.1.3).
Wait for the dev servers to start.
Click "LargeStep" in both windows.
Notice that the styles on the two pages are different.1. Open two links in two browser windows. These two links are the same example but with different astro versions (6.0.8 and 6.1.3)
Wait for the dev servers to start
Click "LargeStep" in both windows
Notice that the styles in two pages are different.
This may or may not be related to the existing issue #16181
What's the expected result?
The UnoCSS styles are loaded as expected.
Link to Minimal Reproducible Example
See description above
Participation
I am willing to submit a pull request for this issue.
I was able to reproduce this issue. The root cause is a regression introduced by commit 999c875da5 ("fix(transitions): auto-persist styles with data-vite-dev-id (#16089)"), merged between Astro 6.0.8 and 6.1.3. The persistedHeadElement function in swap-functions.ts unconditionally preserves old <style data-vite-dev-id> elements during ClientRouter soft navigations, discarding the newer SSR-rendered version. For on-demand CSS tools like UnoCSS, the SSR-rendered __uno.css for a newly navigated page contains additional utility class rules discovered during SSR, but these are thrown away in favor of the stale initial version that lacks them.
I was able to fix this issue. The fix updates the persistedHeadElement function to compare the textContent of the preserved and incoming <style> elements, updating the preserved element's content when the new version differs. This maintains Vite's HMR reference to the DOM element while ensuring on-demand CSS tools like UnoCSS have their latest styles applied. View Suggested Fix
Priority P4: important. This is a dev-mode regression that breaks styling for any project using on-demand CSS tools (UnoCSS, WindiCSS, etc.) combined with ClientRouter (View Transitions) and integration-injected routes. It affects a common workflow — navigating between pages where CSS is progressively generated — and has no user-facing workaround other than pinning to Astro 6.0.8 or doing a full page reload after each navigation.
After updating Astro from 6.0.8 to 6.1.3, UnoCSS styles no longer appear in dev mode. The issue was demonstrated using an astrobook (Storybook-like) project with a Preact counter component that uses UnoCSS utility classes like flex items-center gap-10 p-4 rounded bg-gray-200, etc.
The reporter provided two StackBlitz reproductions:
Working (Astro 6.0.8): https://stackblitz.com/github/issueset/astro-css-issue-6-1-3/tree/6.0.8
The reporter noted this may be related to issue #16181 (styles not always included in dev mode after Astro v6 upgrade).
Reproduction Status: REPRODUCED
Key Findings
Dev mode is broken: The __uno.css virtual module loaded in the browser during dev mode contains only UnoCSS theme variables and base/reset styles (9091 characters). It does NOT contain any utility class rules (.flex, .items-center, .gap-10, .p-4, .rounded, .bg-gray-200, etc.).
Build mode works correctly: Running astro build generates a CSS file that correctly contains all UnoCSS utility classes.
Regular Astro pages work: When adding a standalone .astro page (not via astrobook) with the same UnoCSS classes directly in the template, the styles ARE correctly applied in dev mode. The issue is specific to how components are loaded through integrations like astrobook that inject routes dynamically and use View Transitions for navigation.
The component HTML is correct: The Preact counter component's HTML is rendered correctly in the DOM with all the expected class names. The issue is purely that UnoCSS doesn't generate CSS rules for those classes in the persisted style element.
Root Cause
The bug is caused by commit 999c875da5 — "fix(transitions): auto-persist styles with data-vite-dev-id (#16089)".
The commit added logic to persistedHeadElement that preserves <style data-vite-dev-id="..."> elements across View Transitions (ClientRouter) soft navigations. When navigating from page A to page B, if both pages have a <style> tag with the same data-vite-dev-id, the OLD element is preserved and the NEW element is discarded.
Timing issue:
User loads root page (/): UnoCSS's __uno.css contains only theme/reset CSS (9091 chars)
User clicks "LargeStep" via ClientRouter: SSR renders the story page, UnoCSS scans PreactCounter.tsx, and __uno.css now has 11218 chars (including utility rules)
View Transitions swap: swapHeadElements finds matching data-vite-dev-id="/__uno.css" and preserves the OLD (incomplete) element, discarding the NEW (complete) version
Result: Stale CSS without utility class rules
Fix Applied
The persistedHeadElement function was modified to update the preserved element's textContent when the new SSR-rendered version has different content. This preserves the DOM element (maintaining Vite's HMR reference) while ensuring on-demand CSS content is up to date.
Verification Results
Build succeeded with 0 errors
Dev server reproduction confirmed: UnoCSS utility classes now correctly render after View Transitions navigation
Hi @ocavue sorry for the problems that #16089 caused. Reverting that change might help you, but would also again surface the former issue that PR was supposed to fix. I'll, looking into it.
Could you please provide a minimal reproduction that contains the relevant page in src (i.e. not burried inside node_modules?
Hello @ocavue. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with needs repro will be closed if they have no activity within 3 days.
Activity
ocavue commentedon Apr 3, 2026
Update: it seems that this bug was introduced in astro@6.1.1
astrobot-houston commentedon Apr 3, 2026
I was able to reproduce this issue. The root cause is a regression introduced by commit
999c875da5("fix(transitions): auto-persist styles with data-vite-dev-id (#16089)"), merged between Astro 6.0.8 and 6.1.3. ThepersistedHeadElementfunction inswap-functions.tsunconditionally preserves old<style data-vite-dev-id>elements during ClientRouter soft navigations, discarding the newer SSR-rendered version. For on-demand CSS tools like UnoCSS, the SSR-rendered__uno.cssfor a newly navigated page contains additional utility class rules discovered during SSR, but these are thrown away in favor of the stale initial version that lacks them.I was able to fix this issue. The fix updates the
persistedHeadElementfunction to compare thetextContentof the preserved and incoming<style>elements, updating the preserved element's content when the new version differs. This maintains Vite's HMR reference to the DOM element while ensuring on-demand CSS tools like UnoCSS have their latest styles applied. View Suggested FixPriority P4: important. This is a dev-mode regression that breaks styling for any project using on-demand CSS tools (UnoCSS, WindiCSS, etc.) combined with ClientRouter (View Transitions) and integration-injected routes. It affects a common workflow — navigating between pages where CSS is progressively generated — and has no user-facing workaround other than pinning to Astro 6.0.8 or doing a full page reload after each navigation.
Full Triage Report
Triage Report: Issue #16204
Issue Title
Unable to load UnoCSS style after updating astro from 6.0.8 to 6.1.3
Issue Author
@ocavue
Original Issue Description
After updating Astro from 6.0.8 to 6.1.3, UnoCSS styles no longer appear in dev mode. The issue was demonstrated using an
astrobook(Storybook-like) project with a Preact counter component that uses UnoCSS utility classes likeflex items-center gap-10 p-4 rounded bg-gray-200, etc.The reporter provided two StackBlitz reproductions:
https://stackblitz.com/github/issueset/astro-css-issue-6-1-3/tree/6.0.8https://stackblitz.com/github/issueset/astro-css-issue-6-1-3/tree/6.1.3The reporter noted this may be related to issue #16181 (styles not always included in dev mode after Astro v6 upgrade).
Reproduction Status: REPRODUCED
Key Findings
Dev mode is broken: The
__uno.cssvirtual module loaded in the browser during dev mode contains only UnoCSS theme variables and base/reset styles (9091 characters). It does NOT contain any utility class rules (.flex,.items-center,.gap-10,.p-4,.rounded,.bg-gray-200, etc.).Build mode works correctly: Running
astro buildgenerates a CSS file that correctly contains all UnoCSS utility classes.Regular Astro pages work: When adding a standalone
.astropage (not via astrobook) with the same UnoCSS classes directly in the template, the styles ARE correctly applied in dev mode. The issue is specific to how components are loaded through integrations like astrobook that inject routes dynamically and use View Transitions for navigation.The component HTML is correct: The Preact counter component's HTML is rendered correctly in the DOM with all the expected class names. The issue is purely that UnoCSS doesn't generate CSS rules for those classes in the persisted style element.
Root Cause
The bug is caused by commit
999c875da5— "fix(transitions): auto-persist styles with data-vite-dev-id (#16089)".Affected file:
packages/astro/src/transitions/swap-functions.ts, lines 189-198The commit added logic to
persistedHeadElementthat preserves<style data-vite-dev-id="...">elements across View Transitions (ClientRouter) soft navigations. When navigating from page A to page B, if both pages have a<style>tag with the samedata-vite-dev-id, the OLD element is preserved and the NEW element is discarded.Timing issue:
/): UnoCSS's__uno.csscontains only theme/reset CSS (9091 chars)PreactCounter.tsx, and__uno.cssnow has 11218 chars (including utility rules)swapHeadElementsfinds matchingdata-vite-dev-id="/__uno.css"and preserves the OLD (incomplete) element, discarding the NEW (complete) versionFix Applied
The
persistedHeadElementfunction was modified to update the preserved element'stextContentwhen the new SSR-rendered version has different content. This preserves the DOM element (maintaining Vite's HMR reference) while ensuring on-demand CSS content is up to date.Verification Results
:deep()fix preserved (content comparison is no-op when identical)This report was made by an LLM. Mistakes happen, check important info.
martrapp commentedon Apr 4, 2026
Hi @ocavue sorry for the problems that #16089 caused. Reverting that change might help you, but would also again surface the former issue that PR was supposed to fix. I'll, looking into it.
Could you please provide a minimal reproduction that contains the relevant page in src (i.e. not burried inside node_modules?
github-actions commentedon Apr 4, 2026
Hello @ocavue. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with
needs reprowill be closed if they have no activity within 3 days.ocavue commentedon Apr 7, 2026
Updated reproduction: https://github.com/issueset/astro-css-issue-6-1-3/tree/with-only-unocss
Steps to reproduce:
CleanShot.2026-04-07.at.19.16.18.mp4
martrapp commentedon Apr 7, 2026
Thank you, @ocavue! A fix is on its way.
ocavue commentedon Apr 9, 2026
@martrapp Thanks for your quick fix!