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
[v6] Styles for Vue Components set with :deep are not applied during Dev when using ClientRouter #15898
- P3: minor bugAn edge case that only affects very specific usage (priority)pkg: astroRelated to the core `astro` package (scope)pkg: vueRelated to Vue (scope)
Astro v6.0.4
Vite v7.3.1
Node v22.22.0
System Linux (x64)
Package Manager npm
Output static
Adapter none
Integrations @astrojs/vue (v6.0.0)
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
Vue components typically have scoped styles. Sometimes, it is necessary to "break into" those scoped styles from a parent component to change things. For this, Vue provides the :deep-selector.
After upgrading to Astro v6, these styles set via the :deep-selector are no longer applied when running in dev mode with the <ClientRouter /> Astro component active. They appear (delayed) after the first load and a hard refresh, but navigating between pages does not apply them correctly.
Removing <ClientRouter /> fixes the issue. It doesn't seem like there is a correlation between components being hydrated with a client: directive or not, the issue persists in both cases.
After the site is built, the issue does not occur.
What's the expected result?
Styles applied with :deep are consistently applied on client-side navigations. Behaviour during dev matches that after build.
@astrobot-houston would would be so kind to PTAL, your last run didn't complete. :deep() works with the client router for client:only but fails when used with client:load in dev mode.
Vite's client code in dev mode translates
&:deep(p) {
color: white;
}
into
&[data-v-50f77a40] p {
color: white;
}
but that transform is only triggered on the initial load, not during the client router's soft navigation.
find out, how we can trigger the transform in devmode during astros view transitions
I was able to reproduce this issue. In dev mode, Vite injects <style data-vite-dev-id="..."> elements whose textContent is later transformed by HMR — for example, Vue's :deep(p) becomes [data-v-xxx] p. When the ClientRouter performs a soft navigation, the persistedHeadElement function in swap-functions.ts does not recognize these Vite dev styles by their data-vite-dev-id attribute, so the already-transformed <style> element is discarded and replaced with the raw (untransformed) version from the new document. This causes :deep() styles to stop working after the first client-side navigation.
I was able to fix this issue. The fix adds a match for <style> elements by their data-vite-dev-id attribute in the persistedHeadElement function, so the already-HMR-transformed style element is preserved across ClientRouter soft navigations instead of being replaced by the raw version. View Suggested Fix
Priority P3: minor bug. This affects users who combine Vue scoped styles using :deep() with Astro's <ClientRouter /> in dev mode only — production builds are unaffected. Workarounds include performing a hard refresh or temporarily removing the ClientRouter during development.
Full Triage Report
No report.md was generated by previous triage steps. The following analysis was derived from the issue description, maintainer comments, and the fix branch.
Reproduction
The issue reproduces when using Vue components with :deep() scoped styles alongside Astro's <ClientRouter /> in dev mode. Styles appear correctly on initial hard load but are lost after soft (client-side) navigations.
Root Cause
In dev mode, Vite injects <style data-vite-dev-id="..."> elements into the document head. These styles are initially raw CSS that gets transformed by Vite's HMR client — for Vue components, :deep(p) is rewritten to [data-v-xxx] p.
During a ClientRouter soft navigation, the function persistedHeadElement in packages/astro/src/transitions/swap-functions.ts determines which <head> elements to preserve vs. replace. It had no logic to match Vite dev styles by their data-vite-dev-id attribute, so the already-transformed <style> was replaced with the raw version fetched from the new page. The raw version had not yet been processed by Vite's HMR, so the :deep() selector remained untransformed and did not match any elements.
Fix
The fix (1 file changed, 10 insertions) adds a new matching case in persistedHeadElement (packages/astro/src/transitions/swap-functions.ts:189-198):
This ensures that Vite dev style elements are matched by their stable data-vite-dev-id, preserving the already-HMR-transformed content across soft navigations. Production builds are unaffected since data-vite-dev-id is only present in dev mode.
This report was made by an LLM. Mistakes happen, check important info.
Sure thing! I think it might be related to the use of preprocessors, as my minimal example above works fine if upgraded to the latest Astro version, but starts breaking once a CSS preprocessor such as SASS is added:
- P3: minor bugAn edge case that only affects very specific usage (priority)pkg: astroRelated to the core `astro` package (scope)pkg: vueRelated to Vue (scope)
Activity
fix(css): reorder dev CSS cache transform to run after framework plug…
martrapp commentedon Mar 25, 2026
@astrobot-houston would would be so kind to PTAL, your last run didn't complete.
:deep()works with the client router forclient:onlybut fails when used withclient:loadin dev mode.Vite's client code in dev mode translates
into
but that transform is only triggered on the initial load, not during the client router's soft navigation.
find out, how we can trigger the transform in devmode during astros view transitions
astrobot-houston commentedon Mar 25, 2026
I was able to reproduce this issue. In dev mode, Vite injects
<style data-vite-dev-id="...">elements whosetextContentis later transformed by HMR — for example, Vue's:deep(p)becomes[data-v-xxx] p. When the ClientRouter performs a soft navigation, thepersistedHeadElementfunction inswap-functions.tsdoes not recognize these Vite dev styles by theirdata-vite-dev-idattribute, so the already-transformed<style>element is discarded and replaced with the raw (untransformed) version from the new document. This causes:deep()styles to stop working after the first client-side navigation.I was able to fix this issue. The fix adds a match for
<style>elements by theirdata-vite-dev-idattribute in thepersistedHeadElementfunction, so the already-HMR-transformed style element is preserved across ClientRouter soft navigations instead of being replaced by the raw version. View Suggested FixPriority P3: minor bug. This affects users who combine Vue scoped styles using
:deep()with Astro's<ClientRouter />in dev mode only — production builds are unaffected. Workarounds include performing a hard refresh or temporarily removing the ClientRouter during development.Full Triage Report
No
report.mdwas generated by previous triage steps. The following analysis was derived from the issue description, maintainer comments, and the fix branch.Reproduction
The issue reproduces when using Vue components with
:deep()scoped styles alongside Astro's<ClientRouter />in dev mode. Styles appear correctly on initial hard load but are lost after soft (client-side) navigations.Root Cause
In dev mode, Vite injects
<style data-vite-dev-id="...">elements into the document head. These styles are initially raw CSS that gets transformed by Vite's HMR client — for Vue components,:deep(p)is rewritten to[data-v-xxx] p.During a ClientRouter soft navigation, the function
persistedHeadElementinpackages/astro/src/transitions/swap-functions.tsdetermines which<head>elements to preserve vs. replace. It had no logic to match Vite dev styles by theirdata-vite-dev-idattribute, so the already-transformed<style>was replaced with the raw version fetched from the new page. The raw version had not yet been processed by Vite's HMR, so the:deep()selector remained untransformed and did not match any elements.Fix
The fix (1 file changed, 10 insertions) adds a new matching case in
persistedHeadElement(packages/astro/src/transitions/swap-functions.ts:189-198):This ensures that Vite dev style elements are matched by their stable
data-vite-dev-id, preserving the already-HMR-transformed content across soft navigations. Production builds are unaffected sincedata-vite-dev-idis only present in dev mode.This report was made by an LLM. Mistakes happen, check important info.
amxmln commentedon Apr 17, 2026
This issue now happens again since
v6.1.5when #16242 reverted some of the changes of #16089.I think this should be reopened.
martrapp commentedon Apr 17, 2026
Hi @amxmln 👋,
thank you for the heads up! I'm currently reworking the fix in the light of #16334.
Could you do me a favour and tell me the
data-vite-dev-ids of the styles that do not work for you?amxmln commentedon Apr 17, 2026
Sure thing! I think it might be related to the use of preprocessors, as my minimal example above works fine if upgraded to the latest Astro version, but starts breaking once a CSS preprocessor such as SASS is added:
Breaking:
data-vite-dev-id="/home/projects/github-5h86mej1/src/components/ComponentWithScopedStyles.vue?vue&type=style&index=0&scoped=50f77a40&lang.scss"Working:
data-vite-dev-id="/home/projects/github-5h86mej1/src/components/ComponentWithScopedStyles.vue?vue&type=style&index=0&scoped=50f77a40&lang.css"martrapp commentedon Apr 17, 2026
Great, the new version doesn't insist on the file extension, see #16334 (comment)
So scss and others should work fine, too.