Skip to content

Commit 5c888c1

Browse files
martrappsarah11918
andauthored
Fix: Persist styles of persistent client:only components during view transitions in DEV mode (#8840)
* Persist styles of persistent client:only components during view transitions * Persist styles of persistent client:only components during view transitions * Persist styles of persistent client:only components during view transitions * reset flag for persistent style shhets before re-calculating * new approach with a clear module loader cache * simplifications * wait for hydration * improve changeset message * improve changeset message * please the linter * additional tests for Svelte and Vue * tidy up * test fixed * test w/o persistence * Update .changeset/purple-dots-refuse.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> --------- Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
1 parent 740c916 commit 5c888c1

File tree

16 files changed

+225
-13
lines changed

16 files changed

+225
-13
lines changed

.changeset/purple-dots-refuse.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Fixes styles of `client:only` components not persisting during view transitions in dev mode

packages/astro/e2e/fixtures/view-transitions/astro.config.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { defineConfig } from 'astro/config';
22
import react from '@astrojs/react';
3+
import vue from '@astrojs/vue';
4+
import svelte from '@astrojs/svelte';
35
import nodejs from '@astrojs/node';
46

57
// https://astro.build/config
68
export default defineConfig({
79
output: 'hybrid',
810
adapter: nodejs({ mode: 'standalone' }),
9-
integrations: [react()],
11+
integrations: [react(),vue(),svelte()],
1012
redirects: {
1113
'/redirect-two': '/two',
1214
'/redirect-external': 'http://example.com/',

packages/astro/e2e/fixtures/view-transitions/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
"astro": "workspace:*",
77
"@astrojs/node": "workspace:*",
88
"@astrojs/react": "workspace:*",
9+
"@astrojs/vue": "workspace:*",
10+
"@astrojs/svelte": "workspace:*",
11+
"svelte": "^4.2.0",
12+
"vue": "^3.3.4",
913
"react": "^18.1.0",
1014
"react-dom": "^18.1.0"
1115
}

packages/astro/e2e/fixtures/view-transitions/src/components/Island.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@
88

99
.counter-message {
1010
text-align: center;
11+
background-color: lightskyblue;
12+
color:black
1113
}

packages/astro/e2e/fixtures/view-transitions/src/components/Island.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { useState } from 'react';
22
import './Island.css';
3+
import { indirect} from './css.js';
34

45
export default function Counter({ children, count: initialCount, id }) {
56
const [count, setCount] = useState(initialCount);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<script lang="ts">
2+
let count = 0;
3+
4+
function add() {
5+
count += 1;
6+
}
7+
8+
function subtract() {
9+
count -= 1;
10+
}
11+
</script>
12+
13+
<div class="counter">
14+
<button on:click={subtract}>-</button>
15+
<pre>{count}</pre>
16+
<button on:click={add}>+</button>
17+
</div>
18+
<div class="message">
19+
<slot />
20+
</div>
21+
22+
<style>
23+
.counter {
24+
display: grid;
25+
font-size: 2em;
26+
grid-template-columns: repeat(3, minmax(0, 1fr));
27+
margin-top: 2em;
28+
place-items: center;
29+
}
30+
31+
.message {
32+
text-align: center;
33+
background-color: maroon;
34+
color: tomato;
35+
}
36+
</style>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<template>
2+
<div class="counter">
3+
<button @click="subtract()">-</button>
4+
<pre>{{ count }}</pre>
5+
<button @click="add()">+</button>
6+
</div>
7+
<div class="counter-message">
8+
<slot />
9+
</div>
10+
</template>
11+
12+
<script lang="ts">
13+
import { ref } from 'vue';
14+
export default {
15+
setup() {
16+
const count = ref(0);
17+
const add = () => (count.value = count.value + 1);
18+
const subtract = () => (count.value = count.value - 1);
19+
20+
return {
21+
count,
22+
add,
23+
subtract,
24+
};
25+
},
26+
};
27+
</script>
28+
29+
<style scoped>
30+
.counter {
31+
display: grid;
32+
font-size: 2em;
33+
grid-template-columns: repeat(3, minmax(0, 1fr));
34+
margin-top: 2em;
35+
place-items: center;
36+
}
37+
38+
.counter-message {
39+
text-align: center;
40+
background: darkgreen;
41+
color: greenyellow;
42+
}
43+
</style>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import "./other.postcss";
2+
export const indirect = "<dummy>";
3+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* not much to see */
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
import Layout from '../components/Layout.astro';
3+
import Island from '../components/Island';
4+
import VueCounter from '../components/VueCounter.vue';
5+
import SvelteCounter from '../components/SvelteCounter.svelte';
6+
---
7+
<Layout>
8+
<p id="page-four">Page 4</p>
9+
<VueCounter client:only="vue">Vue</VueCounter>
10+
<SvelteCounter client:only="svelte">Svelte</SvelteCounter>
11+
</Layout>

0 commit comments

Comments
 (0)