Skip to content

Unable to load UnoCSS style after updating astro from 6.0.8 to 6.1.3 #16204

Closed

Description

@ocavue

Astro Info

Astro                    v6.1.3
Vite                     v7.3.1
Node                     v22.22.0
System                   Linux (x64)
Package Manager          pnpm
Output                   static
Adapter                  none
Integrations             @astrojs/preact (v5.0.2)
                         astrobook (v0.12.6)
                         unocss (v66.6.7)

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

Chrome

Describe the Bug

After updating astro from 6.0.8 to 6.1.3, I found that the style won't appear anymore.

I've prepared two minimal reproductions:

Steps to reproduce:

  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).
  2. Wait for the dev servers to start.
  3. Click "LargeStep" in both windows.
  4. 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)
  5. Wait for the dev servers to start
  6. Click "LargeStep" in both windows
  7. Notice that the styles in two pages are different.
Image

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.

Activity

  1. added
    triage: needs triage
    on Apr 3, 2026
  2. ocavue commented on Apr 3, 2026

    @ocavue
    ContributorAuthor

    Update: it seems that this bug was introduced in astro@6.1.1

    • astro@6.0.8: good
    • astro@6.1.0: good
    • astro@6.1.1: bad
    • astro@6.1.2: bad
    • astro@6.1.3: bad
  3. astrobot-houston commented on Apr 3, 2026

    @astrobot-houston
    Contributor

    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.

    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 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
    • Broken (Astro 6.1.3): https://stackblitz.com/github/issueset/astro-css-issue-6-1-3/tree/6.1.3

    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

    1. 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.).

    2. Build mode works correctly: Running astro build generates a CSS file that correctly contains all UnoCSS utility classes.

    3. 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.

    4. 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-198

    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:

    1. User loads root page (/): UnoCSS's __uno.css contains only theme/reset CSS (9091 chars)
    2. User clicks "LargeStep" via ClientRouter: SSR renders the story page, UnoCSS scans PreactCounter.tsx, and __uno.css now has 11218 chars (including utility rules)
    3. View Transitions swap: swapHeadElements finds matching data-vite-dev-id="/__uno.css" and preserves the OLD (incomplete) element, discarding the NEW (complete) version
    4. 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

    1. Build succeeded with 0 errors
    2. Dev server reproduction confirmed: UnoCSS utility classes now correctly render after View Transitions navigation
    3. All existing tests pass (view-transitions: 2/2, transitions unit: 26/26, css: 1/1)
    4. Original Vue :deep() fix preserved (content comparison is no-op when identical)

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

  4. added
    - P4: important
    pkg: astro
    and removed
    triage: needs triage
    on Apr 3, 2026
  5. martrapp commented on Apr 4, 2026

    @martrapp
    Member

    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?

  6. self-assigned this
    on Apr 4, 2026
  7. added
    triage: needs reproduction
    on Apr 4, 2026
  8. github-actions commented on Apr 4, 2026

    @github-actions
    Contributor

    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.

  9. added
    - P3: minor bug
    and removed
    - P4: important
    on Apr 4, 2026
  10. ocavue commented on Apr 7, 2026

    @ocavue
    ContributorAuthor

    Could you please provide a minimal reproduction that contains the relevant page in src (i.e. not burried inside node_modules?

    Updated reproduction: https://github.com/issueset/astro-css-issue-6-1-3/tree/with-only-unocss

    Steps to reproduce:

    1. Install
    $ git clone https://github.com/issueset/astro-css-issue-6-1-3 -b with-only-unocss
    $ cd astro-css-issue-6-1-3
    $ pnpm install 
    $ pnpm run dev
    
    1. Open the dev server in the browser
    2. Click "Page A1"
    CleanShot.2026-04-07.at.19.16.18.mp4
  11. removed
    triage: needs reproduction
    on Apr 7, 2026
  12. martrapp commented on Apr 7, 2026

    @martrapp
    Member

    Thank you, @ocavue! A fix is on its way.

  13. ocavue commented on Apr 9, 2026

    @ocavue
    ContributorAuthor

    @martrapp Thanks for your quick fix!

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

Metadata

Metadata

Assignees

Labels

- P3: minor bugpkg: astro

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions