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 with @apply and --at-apply #16373
- P3: minor bugAn edge case that only affects very specific usage (priority)- P4: importantViolate documented behavior or significantly impacts performance (priority)pkg: astroRelated to the core `astro` package (scope)triage: fix pendingReporter needs to verify the triage bot fix works
I was able to reproduce this issue. When using UnoCSS's transformerDirectives (which processes @apply and --at-apply) alongside Astro's View Transitions (ClientRouter), styles break on soft navigations. The root cause is twofold: (1) Astro's dev CSS plugin caches CSS content in its transform hook before integration plugins like UnoCSS have processed directives such as @apply, so the cache stores raw unresolved directives instead of the final utility classes; and (2) during ClientRouter soft navigations, Astro's style persistence logic only preserved Vue-style <style> elements but not Astro component styles, causing processed styles to be replaced with their unprocessed raw versions from the new document.
I was able to fix this issue. The fix extracts the CSS caching transform into a separate plugin (astro:dev-css-cache) that is registered in the Vite plugin chain after integration plugins, ensuring it caches fully-processed CSS. It also extends the style persistence logic in swap-functions.ts to auto-persist Astro component <style> elements (matching ?astro&type=style&...lang.css) during ClientRouter navigations, preventing them from being replaced by unprocessed versions. View Suggested Fix
P4: important. This bug affects any user combining UnoCSS directive transforms (@apply/--at-apply) with Astro's View Transitions in dev mode — a common setup for Tailwind-like utility workflows. Styles silently break on every soft navigation, making the dev experience unusable for this combination. It does not affect production builds (which use Rollup and process transforms correctly).
The issue occurs in astro dev when using UnoCSS's transformerDirectives with @apply/--at-apply and Astro View Transitions (ClientRouter). On the initial page load, styles render correctly. After a soft navigation (clicking a link), UnoCSS-processed styles disappear.
Diagnosis
Root Cause 1 — CSS cache ordering (packages/astro/src/vite-plugin-css/index.ts)
The astro:dev-css plugin included a transform hook that cached CSS content by module ID. This transform ran as part of Astro's core plugin set, which is registered before integration plugins in the Vite config. UnoCSS's transformerDirectives processes @apply directives during its own transform hook. Because Vite executes plugin transforms in registration order, Astro's cache captured the CSS before UnoCSS had resolved the @apply directives. When the ClientRouter requested CSS for a new route, it served the cached (unprocessed) content containing raw @apply — which browsers cannot interpret.
Root Cause 2 — Style persistence during navigation (packages/astro/src/transitions/swap-functions.ts)
During ClientRouter soft navigations, persistedHeadElement auto-persists certain <style> elements to avoid replacing HMR-applied (fully-processed) styles with raw (unprocessed) versions from the server-rendered HTML. This logic only matched Vue dev styles (?vue&type=style&...lang.css) but not Astro component styles (?astro&type=style&...lang.css). Astro component styles processed by UnoCSS were therefore replaced on every navigation.
Fix
File: packages/astro/src/vite-plugin-css/index.ts
Extracted the CSS caching transform into a new standalone plugin astro:dev-css-cache
The new plugin shares the same cssContentCache Map via closure
Changed astroDevCssPlugin to return { plugins, cssCachePlugin } instead of a flat plugin array
File: packages/astro/src/core/create-vite.ts
Registers devCss.plugins in the normal plugin position
Pushes devCss.cssCachePlugin to the end of the plugin array after integration plugins have been merged, ensuring integration transforms (UnoCSS, etc.) run before caching
@astrobot-houston, you ran your triage on an older version of astro. Swap functions have ben changed yesterday. could please re-triage with the current state?
Priority:P4: important. This affects any user combining UnoCSS directive transforms (@apply/--at-apply) with Astro's ClientRouter in dev mode — a common Tailwind-like utility workflow. Styles silently break on every soft navigation, making the dev experience unusable for this combination.
The root cause is twofold: (1) Astro's astro:dev-css plugin caches CSS in its transform hook before integration plugins like UnoCSS have processed directives such as @apply, so the cache stores raw unresolved directives instead of the final utility classes; and (2) during ClientRouter soft navigations, the style persistence logic (updated in PRs #16242 and #16379) only preserves Vue scoped <style> elements but not Astro component styles, so the HMR-processed styles get replaced with unprocessed versions from the server-rendered HTML. Production builds are not affected.
I found a potential fix for this issue. The fix extracts the CSS caching transform into a separate plugin (astro:dev-css-cache) registered after integration plugins, ensuring the cache stores fully-processed CSS. It also extends the style persistence logic to handle Astro component styles (?astro&type=style) during ClientRouter navigations as defense-in-depth. All existing CSS and view-transition tests pass.
The issue occurs in astro dev when using UnoCSS's transformerDirectives with @apply/--at-apply and Astro View Transitions (ClientRouter). On initial page load, styles render correctly. After a soft navigation (clicking a link), UnoCSS-processed styles disappear because the <style> element gets replaced with its raw, unprocessed version containing literal @apply directives.
Baseline Verification
Hard page loads always work correctly (styles are properly resolved)
Direct UnoCSS utility classes on elements (e.g., class="bg-red-500 p-10 m-10") work correctly even after soft navigation — the issue is specific to @apply/--at-apply directive-transformed styles within component <style> blocks
The astro:dev-css plugin's transform hook caches CSS content by module ID. This plugin is registered at create-vite.ts:190 in Astro's core plugin array, before integration plugins (UnoCSS) are merged at create-vite.ts:320 via vite.mergeConfig(). Vite runs transform hooks in plugin registration order, so:
Astro's astro:dev-css transform runs first → cssContentCache.set(id, code) stores raw CSS containing @apply
UnoCSS's transformerDirectives transform runs after → resolves @apply into actual CSS properties
The fully-processed CSS goes to Vite's module graph, but cssContentCache retains the raw version
When the ClientRouter fetches CSS for a new route via the dev CSS virtual module, it reads from cssContentCache (line 237), which contains the unprocessed version. On initial hard page load, this raw inline <style> gets overridden by Vite's client-side CSS module system, which executes all transforms in the correct order. The problem only manifests during soft navigation.
Introduced by the Environment API refactor (commit 141c4a26419, PR #14306). No comment or evidence that integration transform ordering was considered.
Root Cause 2: Style Non-Persistence During Soft Navigation
File:packages/astro/src/transitions/swap-functions.ts, lines 58-85 and 190-245
PR #16379 added two mechanisms for Vue scoped styles that do not extend to Astro component styles:
persistedHeadElement (lines 221-226): Only matches Vue scoped styles via vueScopedStyleId(). Astro component styles (?astro&type=style&index=0&lang.css) are not matched.
knownVueScopedStyles map (lines 11, 66-70, 77-84): Before removing old styles, Vue scoped styles are saved for reuse. Astro component styles are not saved.
PR #16242 deliberately narrowed persistedHeadElement from matching alldata-vite-dev-id styles to only Vue styles because UnoCSS's /__uno.css has the same ID on every page but with different content. This narrowing was correct for /__uno.css but overly broad — it also excluded Astro component styles, which have stable content when the same component appears on multiple pages.
Fix Details
Fix 1: CSS Cache Plugin Ordering (Primary)
packages/astro/src/vite-plugin-css/index.ts: Extracted the CSS caching transform hook into a separate standalone plugin astro:dev-css-cache. The function now returns { plugins, cssCachePlugin } instead of a flat Plugin[] array. The cache plugin shares the same cssContentCache Map via closure.
packages/astro/src/core/create-vite.ts: Registers devCss.plugins in the normal position. Pushes devCss.cssCachePlugin to the end of the plugin array after integration plugins have been merged, ensuring integration transforms run before caching.
Added astroComponentStyleId() function (analogous to vueScopedStyleId()) matching ?astro + type=style in data-vite-dev-id
Extended persistedHeadElement() to also persist Astro component styles
Added knownAstroComponentStyles map (analogous to knownVueScopedStyles)
Updated swapHeadElements() to check both maps when appending new elements
/__uno.css is NOT affected because it does not match the ?astro&type=style pattern.
Test Update
packages/astro/test/0-css.test.js: Updated "resolves CSS from Vue" test assertion to account for Vue scoped styles now including the data-v- scope attribute in cached CSS.
Verification
Inline <style> in server-rendered HTML now contains fully-resolved CSS instead of raw @apply
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.
We already had a version where the client router persisted all styles, including unoCSS. (#16204)
The consequence was that unoCSS did not work at all, as new styles from the server were not updated.
The fix (#16242) was to explicitely exclude unoCSS and all non Vue styles from auto-persistence.
Houstons proposal to cache all astro styles might help for @apply but it will most likely harm unoCSS in general.
I have no idea what the proposed change to vites pipeline does and I'm pretty sure I will not mess with that ;-) Specialists welcome!
There is no problem for production, "only" in DEV mode. Page refresh gets the styles right.
What we see here is that the vite ecosystem does cool things with module scripts and and we hit some technical limitations of what the client router can do. We are not able to reload module scripts during soft navigation in the same way as the browser does on MPA navigation.
I am open for good ideas on how to solve this! In the meantime, watch out for https://bugzilla.mozilla.org/show_bug.cgi?id=1860854 which will hopefully be closed this year (as part of Interop 2026) and brings browser native cross document view transitions to all major browsers.
Unit Test: Yes — test/units/dev/css-cache-plugin-ordering.test.ts
Priority:P4: important. This affects any user combining UnoCSS directive transforms (@apply/--at-apply) with Astro's ClientRouter in dev mode — a common Tailwind-like utility workflow. Styles silently break on every soft navigation, making the dev experience unusable for this combination. Production builds and hard page loads are not affected.
The root cause is in the Vite plugin ordering for CSS caching. Astro's astro:dev-css plugin caches CSS in its transform hook, which runs before integration plugins like UnoCSS in the Vite pipeline. This means the cache stores raw @apply directives instead of the resolved CSS. During ClientRouter soft navigations, the server serves HTML with these unprocessed styles — which browsers cannot interpret. This fix does not touch swap-functions.ts or the style persistence logic, respecting @martrapp's feedback about the risks of persisting non-Vue styles.
I found a potential fix for this issue. The fix extracts the CSS caching transform into a separate plugin (astro:dev-css-cache) that is registered in the Vite plugin chain after integration plugins are merged, ensuring the cache stores fully-processed CSS. All existing CSS and view-transition tests pass (100+ tests across 10 test suites).
Try this fix
You can test this fix right now without waiting for a release:
npm i https://pkg.pr.new/astro@2dd544c
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.
The issue occurs in astro dev when using UnoCSS's transformerDirectives with @apply/--at-apply and Astro View Transitions (ClientRouter). On initial page load, styles render correctly. After a soft navigation (clicking a link), UnoCSS-processed styles disappear because the <style> element gets replaced with its raw, unprocessed version containing literal @apply directives.
Baseline Verification
Hard page loads always work correctly (styles are properly resolved)
Direct UnoCSS utility classes on elements (e.g., class="bg-red-500 p-10 m-10") work correctly even after soft navigation — the issue is specific to @apply/--at-apply directive-transformed styles within component <style> blocks
The astro:dev-css plugin's transform hook caches CSS content by module ID. This plugin is registered at create-vite.ts:205 in Astro's core plugin array, before integration plugins (UnoCSS) are merged at create-vite.ts:335 via vite.mergeConfig(). Vite runs transform hooks in plugin registration order, so:
Astro's astro:dev-css transform runs first → cssContentCache.set(id, code) stores raw CSS containing @apply
UnoCSS's transformerDirectives transform runs after → resolves @apply into actual CSS properties
The fully-processed CSS goes to Vite's module graph, but cssContentCache retains the raw version
When the ClientRouter fetches CSS for a new route via the dev CSS virtual module, it reads from cssContentCache (line 237), which contains the unprocessed version. On initial hard page load, this raw inline <style> gets overridden by Vite's client-side CSS module system, which executes all transforms in the correct order. The problem only manifests during soft navigation.
Introduced by the Environment API refactor (commit 141c4a26419, PR #14306). No comment or evidence that integration transform ordering was considered.
Instrumentation Confirmation
Debug logging confirmed the cssContentCache stores raw @apply directives and serves that same raw CSS in the HTML response:
Extracted the CSS caching transform into a new standalone plugin astro:dev-css-cache
Changed astroDevCssPlugin to return { plugins, cssCachePlugin } instead of a flat Plugin[] array
The cache plugin shares the same cssContentCache Map via closure
packages/astro/src/core/create-vite.ts:
Registers devCss.plugins in the normal plugin position
Appends devCss.cssCachePlugin to the end of the plugin array after integration plugins have been merged, ensuring integration transforms (UnoCSS, etc.) run before caching
packages/astro/test/0-css.test.ts:
Updated "resolves CSS from Vue" assertion from .vue-scoped{ to .vue-scoped[data-v- because the CSS cache now runs after Vue's scoped rewrite
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.
- P3: minor bugAn edge case that only affects very specific usage (priority)- P4: importantViolate documented behavior or significantly impacts performance (priority)pkg: astroRelated to the core `astro` package (scope)triage: fix pendingReporter needs to verify the triage bot fix works
Activity
astrobot-houston commentedon Apr 17, 2026
I was able to reproduce this issue. When using UnoCSS's
transformerDirectives(which processes@applyand--at-apply) alongside Astro's View Transitions (ClientRouter), styles break on soft navigations. The root cause is twofold: (1) Astro's dev CSS plugin caches CSS content in itstransformhook before integration plugins like UnoCSS have processed directives such as@apply, so the cache stores raw unresolved directives instead of the final utility classes; and (2) during ClientRouter soft navigations, Astro's style persistence logic only preserved Vue-style<style>elements but not Astro component styles, causing processed styles to be replaced with their unprocessed raw versions from the new document.I was able to fix this issue. The fix extracts the CSS caching transform into a separate plugin (
astro:dev-css-cache) that is registered in the Vite plugin chain after integration plugins, ensuring it caches fully-processed CSS. It also extends the style persistence logic inswap-functions.tsto auto-persist Astro component<style>elements (matching?astro&type=style&...lang.css) during ClientRouter navigations, preventing them from being replaced by unprocessed versions. View Suggested FixP4: important. This bug affects any user combining UnoCSS directive transforms (
@apply/--at-apply) with Astro's View Transitions in dev mode — a common setup for Tailwind-like utility workflows. Styles silently break on every soft navigation, making the dev experience unusable for this combination. It does not affect production builds (which use Rollup and process transforms correctly).Full Triage Report
Reproduction
@applyand--at-apply#16373 — Unable to load UnoCSS style with@applyand--at-applyThe issue occurs in
astro devwhen using UnoCSS'stransformerDirectiveswith@apply/--at-applyand Astro View Transitions (ClientRouter). On the initial page load, styles render correctly. After a soft navigation (clicking a link), UnoCSS-processed styles disappear.Diagnosis
Root Cause 1 — CSS cache ordering (
packages/astro/src/vite-plugin-css/index.ts)The
astro:dev-cssplugin included atransformhook that cached CSS content by module ID. This transform ran as part of Astro's core plugin set, which is registered before integration plugins in the Vite config. UnoCSS'stransformerDirectivesprocesses@applydirectives during its owntransformhook. Because Vite executes plugin transforms in registration order, Astro's cache captured the CSS before UnoCSS had resolved the@applydirectives. When the ClientRouter requested CSS for a new route, it served the cached (unprocessed) content containing raw@apply— which browsers cannot interpret.Root Cause 2 — Style persistence during navigation (
packages/astro/src/transitions/swap-functions.ts)During ClientRouter soft navigations,
persistedHeadElementauto-persists certain<style>elements to avoid replacing HMR-applied (fully-processed) styles with raw (unprocessed) versions from the server-rendered HTML. This logic only matched Vue dev styles (?vue&type=style&...lang.css) but not Astro component styles (?astro&type=style&...lang.css). Astro component styles processed by UnoCSS were therefore replaced on every navigation.Fix
File:
packages/astro/src/vite-plugin-css/index.tstransforminto a new standalone pluginastro:dev-css-cachecssContentCacheMap via closureastroDevCssPluginto return{ plugins, cssCachePlugin }instead of a flat plugin arrayFile:
packages/astro/src/core/create-vite.tsdevCss.pluginsin the normal plugin positiondevCss.cssCachePluginto the end of the plugin array after integration plugins have been merged, ensuring integration transforms (UnoCSS, etc.) run before cachingFile:
packages/astro/src/transitions/swap-functions.ts/\?astro&type=style&.*lang\.css$/This report was made by an LLM. Mistakes happen, check important info.
refactor(vite-plugin-css): extract CSS caching into separate plugin
fix(transitions): persist Astro component styles during ClientRouter …
docs(changeset): add fix for withastro#16373 UnoCSS View Transitions …
martrapp commentedon Apr 18, 2026
@astrobot-houston, you ran your triage on an older version of astro. Swap functions have ben changed yesterday. could please re-triage with the current state?
fix(css): cache CSS after integration transforms to fix UnoCSS @apply …
astrobot-houston commentedon Apr 18, 2026
main(including swap-functions changes from PR Improves Vue scoped style handling in DEV mode during client router navigation. #16379).@apply/--at-apply) with Astro's ClientRouter in dev mode — a common Tailwind-like utility workflow. Styles silently break on every soft navigation, making the dev experience unusable for this combination.The root cause is twofold: (1) Astro's
astro:dev-cssplugin caches CSS in itstransformhook before integration plugins like UnoCSS have processed directives such as@apply, so the cache stores raw unresolved directives instead of the final utility classes; and (2) during ClientRouter soft navigations, the style persistence logic (updated in PRs #16242 and #16379) only preserves Vue scoped<style>elements but not Astro component styles, so the HMR-processed styles get replaced with unprocessed versions from the server-rendered HTML. Production builds are not affected.I found a potential fix for this issue. The fix extracts the CSS caching transform into a separate plugin (
astro:dev-css-cache) registered after integration plugins, ensuring the cache stores fully-processed CSS. It also extends the style persistence logic to handle Astro component styles (?astro&type=style) during ClientRouter navigations as defense-in-depth. All existing CSS and view-transition tests pass.Full Triage Report
Reproduction
@applyand--at-apply#16373 — Unable to load UnoCSS style with@applyand--at-applymain(commit688044f59a, including PR Improves Vue scoped style handling in DEV mode during client router navigation. #16379 swap-functions changes as requested by @martrapp)The issue occurs in
astro devwhen using UnoCSS'stransformerDirectiveswith@apply/--at-applyand Astro View Transitions (ClientRouter). On initial page load, styles render correctly. After a soft navigation (clicking a link), UnoCSS-processed styles disappear because the<style>element gets replaced with its raw, unprocessed version containing literal@applydirectives.Baseline Verification
class="bg-red-500 p-10 m-10") work correctly even after soft navigation — the issue is specific to@apply/--at-applydirective-transformed styles within component<style>blocksastro build) are not affectedRoot Cause Analysis
Root Cause 1: CSS Cache Ordering (Primary Issue)
File:
packages/astro/src/vite-plugin-css/index.ts, lines 256-275The
astro:dev-cssplugin'stransformhook caches CSS content by module ID. This plugin is registered atcreate-vite.ts:190in Astro's core plugin array, before integration plugins (UnoCSS) are merged atcreate-vite.ts:320viavite.mergeConfig(). Vite runs transform hooks in plugin registration order, so:astro:dev-csstransform runs first →cssContentCache.set(id, code)stores raw CSS containing@applytransformerDirectivestransform runs after → resolves@applyinto actual CSS propertiescssContentCacheretains the raw versionWhen the ClientRouter fetches CSS for a new route via the dev CSS virtual module, it reads from
cssContentCache(line 237), which contains the unprocessed version. On initial hard page load, this raw inline<style>gets overridden by Vite's client-side CSS module system, which executes all transforms in the correct order. The problem only manifests during soft navigation.Introduced by the Environment API refactor (commit
141c4a26419, PR #14306). No comment or evidence that integration transform ordering was considered.Root Cause 2: Style Non-Persistence During Soft Navigation
File:
packages/astro/src/transitions/swap-functions.ts, lines 58-85 and 190-245PR #16379 added two mechanisms for Vue scoped styles that do not extend to Astro component styles:
persistedHeadElement(lines 221-226): Only matches Vue scoped styles viavueScopedStyleId(). Astro component styles (?astro&type=style&index=0&lang.css) are not matched.knownVueScopedStylesmap (lines 11, 66-70, 77-84): Before removing old styles, Vue scoped styles are saved for reuse. Astro component styles are not saved.PR #16242 deliberately narrowed
persistedHeadElementfrom matching alldata-vite-dev-idstyles to only Vue styles because UnoCSS's/__uno.csshas the same ID on every page but with different content. This narrowing was correct for/__uno.cssbut overly broad — it also excluded Astro component styles, which have stable content when the same component appears on multiple pages.Fix Details
Fix 1: CSS Cache Plugin Ordering (Primary)
packages/astro/src/vite-plugin-css/index.ts: Extracted the CSS cachingtransformhook into a separate standalone pluginastro:dev-css-cache. The function now returns{ plugins, cssCachePlugin }instead of a flatPlugin[]array. The cache plugin shares the samecssContentCacheMap via closure.packages/astro/src/core/create-vite.ts: RegistersdevCss.pluginsin the normal position. PushesdevCss.cssCachePluginto the end of the plugin array after integration plugins have been merged, ensuring integration transforms run before caching.Fix 2: Astro Component Style Persistence (Complementary)
packages/astro/src/transitions/swap-functions.ts:astroComponentStyleId()function (analogous tovueScopedStyleId()) matching?astro+type=styleindata-vite-dev-idpersistedHeadElement()to also persist Astro component stylesknownAstroComponentStylesmap (analogous toknownVueScopedStyles)swapHeadElements()to check both maps when appending new elements/__uno.cssis NOT affected because it does not match the?astro&type=stylepattern.Test Update
packages/astro/test/0-css.test.js: Updated "resolves CSS from Vue" test assertion to account for Vue scoped styles now including thedata-v-scope attribute in cached CSS.Verification
<style>in server-rendered HTML now contains fully-resolved CSS instead of raw@apply0-css.test.js(38 pass),css-dynamic-import-dev.test.js,view-transitions.test.js,css-order*.test.js,page-level-styles.test.js,postcss.test.js,tailwindcss.test.js,scoped-style-strategy.test.js,units/render/transitions.test.ts(26 pass)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.
martrapp commentedon Apr 18, 2026
This seems to become a never endig story.
We already had a version where the client router persisted all styles, including unoCSS. (#16204)
The consequence was that unoCSS did not work at all, as new styles from the server were not updated.
The fix (#16242) was to explicitely exclude unoCSS and all non Vue styles from auto-persistence.
Houstons proposal to cache all astro styles might help for @apply but it will most likely harm unoCSS in general.
I have no idea what the proposed change to vites pipeline does and I'm pretty sure I will not mess with that ;-) Specialists welcome!
There is no problem for production, "only" in DEV mode. Page refresh gets the styles right.
What we see here is that the vite ecosystem does cool things with module scripts and and we hit some technical limitations of what the client router can do. We are not able to reload module scripts during soft navigation in the same way as the browser does on MPA navigation.
I am open for good ideas on how to solve this! In the meantime, watch out for https://bugzilla.mozilla.org/show_bug.cgi?id=1860854 which will hopefully be closed this year (as part of Interop 2026) and brings browser native cross document view transitions to all major browsers.
matthewp commentedon May 15, 2026
Astrobot, please rereview this issue and if the fix still works, do a preview release
fix(css): cache CSS after integration transforms to fix UnoCSS @apply …
astrobot-houston commentedon May 15, 2026
main(Astro v6.3.3).test/units/dev/css-cache-plugin-ordering.test.ts@apply/--at-apply) with Astro's ClientRouter in dev mode — a common Tailwind-like utility workflow. Styles silently break on every soft navigation, making the dev experience unusable for this combination. Production builds and hard page loads are not affected.The root cause is in the Vite plugin ordering for CSS caching. Astro's
astro:dev-cssplugin caches CSS in itstransformhook, which runs before integration plugins like UnoCSS in the Vite pipeline. This means the cache stores raw@applydirectives instead of the resolved CSS. During ClientRouter soft navigations, the server serves HTML with these unprocessed styles — which browsers cannot interpret. This fix does not touchswap-functions.tsor the style persistence logic, respecting @martrapp's feedback about the risks of persisting non-Vue styles.I found a potential fix for this issue. The fix extracts the CSS caching transform into a separate plugin (
astro:dev-css-cache) that is registered in the Vite plugin chain after integration plugins are merged, ensuring the cache stores fully-processed CSS. All existing CSS and view-transition tests pass (100+ tests across 10 test suites).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
Reproduction
@applyand--at-apply#16373 — Unable to load UnoCSS style with@applyand--at-applymain(Astro v6.3.3)The issue occurs in
astro devwhen using UnoCSS'stransformerDirectiveswith@apply/--at-applyand Astro View Transitions (ClientRouter). On initial page load, styles render correctly. After a soft navigation (clicking a link), UnoCSS-processed styles disappear because the<style>element gets replaced with its raw, unprocessed version containing literal@applydirectives.Baseline Verification
class="bg-red-500 p-10 m-10") work correctly even after soft navigation — the issue is specific to@apply/--at-applydirective-transformed styles within component<style>blocksastro build) are not affectedRoot Cause Analysis
Root Cause: CSS Cache Ordering
File:
packages/astro/src/vite-plugin-css/index.ts, lines 256-272The
astro:dev-cssplugin'stransformhook caches CSS content by module ID. This plugin is registered atcreate-vite.ts:205in Astro's core plugin array, before integration plugins (UnoCSS) are merged atcreate-vite.ts:335viavite.mergeConfig(). Vite runs transform hooks in plugin registration order, so:astro:dev-csstransform runs first →cssContentCache.set(id, code)stores raw CSS containing@applytransformerDirectivestransform runs after → resolves@applyinto actual CSS propertiescssContentCacheretains the raw versionWhen the ClientRouter fetches CSS for a new route via the dev CSS virtual module, it reads from
cssContentCache(line 237), which contains the unprocessed version. On initial hard page load, this raw inline<style>gets overridden by Vite's client-side CSS module system, which executes all transforms in the correct order. The problem only manifests during soft navigation.Introduced by the Environment API refactor (commit
141c4a26419, PR #14306). No comment or evidence that integration transform ordering was considered.Instrumentation Confirmation
Debug logging confirmed the
cssContentCachestores raw@applydirectives and serves that same raw CSS in the HTML response:Fix
packages/astro/src/vite-plugin-css/index.ts:transforminto a new standalone pluginastro:dev-css-cacheastroDevCssPluginto return{ plugins, cssCachePlugin }instead of a flatPlugin[]arraycssContentCacheMap via closurepackages/astro/src/core/create-vite.ts:devCss.pluginsin the normal plugin positiondevCss.cssCachePluginto the end of the plugin array after integration plugins have been merged, ensuring integration transforms (UnoCSS, etc.) run before cachingpackages/astro/test/0-css.test.ts:.vue-scoped{to.vue-scoped[data-v-because the CSS cache now runs after Vue's scoped rewritepackages/astro/test/units/dev/css-cache-plugin-ordering.test.ts(new):astroDevCssPluginreturns a separatecssCachePluginnot included in the main plugins arrayVerification
Before fix: Server-rendered HTML contained raw
@applydirectives:After fix: Server-rendered HTML contains fully-resolved CSS:
Browser verification after soft navigation:
customBg: blue ✅ (wasrgba(0,0,0,0))applyColor: yellow ✅ (wasrgb(0,0,0))atApplyColor: red ✅ (wasrgb(0,0,0))customPadding: 12px ✅ (was0px)All existing tests pass:
0-css.test.ts(38 pass),css-dynamic-import-dev.test.ts,view-transitions.test.ts,css-order*.test.ts,postcss.test.ts,tailwindcss.test.ts,scoped-style-strategy.test.ts,page-level-styles.test.ts,units/render/transitions.test.ts(26 pass),units/dev/css-cache-plugin-ordering.test.ts(2 pass, new).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.
matthewp commentedon Jun 10, 2026
Fix was not tested, so closing. Please open a new issue if you still have this problem.
fix(dev): 软导航后样式丢失导致要点刷新才正常