-
-
Notifications
You must be signed in to change notification settings - Fork 242
Expand file tree
/
Copy pathnested-rsc-css-hmr.test.ts
More file actions
169 lines (153 loc) · 5.89 KB
/
nested-rsc-css-hmr.test.ts
File metadata and controls
169 lines (153 loc) · 5.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import { expect, test } from '@playwright/test'
import { useFixture } from './fixture'
import { expectNoReload, waitForHydration } from './helper'
// Covers CSS HMR for server-only components rendered via nested Flight stream
// (renderToReadableStream + createFromReadableStream — TanStack Start's
// createServerFn / renderServerComponent shape)
// Fixture uses cssLinkPrecedence: false so React 19 Float dedup/swap is off
// and raw HMR path is exercised
test.describe('nested-rsc-css-hmr', () => {
const f = useFixture({
root: 'examples/nested-rsc-css-hmr',
mode: 'dev',
})
test('css hmr through nested RSC Flight stream', async ({ page }) => {
await page.goto(f.url())
await waitForHydration(page)
await expect(page.locator('.test-nested-rsc-inner')).toHaveCSS(
'color',
'rgb(255, 165, 0)',
)
await using _ = await expectNoReload(page)
const editor = f.createEditor('src/nested-rsc/inner.css')
editor.edit((s) => s.replaceAll('rgb(255, 165, 0)', 'rgb(0, 165, 255)'))
await expect(page.locator('.test-nested-rsc-inner')).toHaveCSS(
'color',
'rgb(0, 165, 255)',
)
// Revert is load-bearing: naive fix lands edit 1 but wedges Vite's
// Promise.all racing React's <link> reconcile, blocking later rsc:update
editor.reset()
await expect(page.locator('.test-nested-rsc-inner')).toHaveCSS(
'color',
'rgb(255, 165, 0)',
)
})
// Rule removal (not just value change) checks the unmount path: old <link>
// must drop, else the cascade keeps the stale rule
test('round-trip with property removal does not leave stale link', async ({
page,
}) => {
await page.goto(f.url())
await waitForHydration(page)
await expect(page.locator('.test-nested-rsc-inner')).toHaveCSS(
'color',
'rgb(255, 165, 0)',
)
// [data-rsc-css-href] scopes to RSC-emitted links, ignores Vite/React
// injections
// Two on load: outer Root collectCss + nested Flight collectCss
// Bug shape is "grows per edit", so assert equal-to-initial, not equal-to-1
const innerLinks = page.locator(
'link[rel="stylesheet"][data-rsc-css-href*="inner.css"]',
)
const initialLinkCount = await innerLinks.count()
expect(initialLinkCount).toBeGreaterThan(0)
await using _ = await expectNoReload(page)
const editor = f.createEditor('src/nested-rsc/inner.css')
// Edit 1: change value
editor.edit((s) => s.replaceAll('rgb(255, 165, 0)', 'rgb(0, 165, 255)'))
await expect(page.locator('.test-nested-rsc-inner')).toHaveCSS(
'color',
'rgb(0, 165, 255)',
)
await expect(innerLinks).toHaveCount(initialLinkCount)
// Edit 2: remove rule — falls back to :root color from index.css
// (rgb(33, 53, 71)) — stale <link> would keep the blue
editor.edit((s) =>
s.replaceAll(
'color: rgb(0, 165, 255);',
'/* color: rgb(0, 165, 255); */',
),
)
await expect(page.locator('.test-nested-rsc-inner')).toHaveCSS(
'color',
'rgb(33, 53, 71)',
)
await expect(innerLinks).toHaveCount(initialLinkCount)
// Edit 3: revert — back to original orange
editor.reset()
await expect(page.locator('.test-nested-rsc-inner')).toHaveCSS(
'color',
'rgb(255, 165, 0)',
)
await expect(innerLinks).toHaveCount(initialLinkCount)
})
// card.module.css reached from RSC graph (card.tsx server component) and
// client graph (client-tracker.tsx 'use client' side-effect import) — shape
// TanStack Start hits when a route re-declares an RSC-owned stylesheet on
// the client
// Exercises the hasClientJsImporter branch of hotUpdate: fix filters the
// CSS-typed module out of the HMR payload (so Vite's default client HMR
// doesn't cloneNode+mutate the RSC <link>) while keeping the JS-typed
// wrapper so updateStyle() keeps refreshing <style data-vite-dev-id>
// .module.css on purpose — plain .css has no JS wrapper to keep
// Tests guard the config shape; they don't repro the (timing-sensitive)
// hydration race
test('css module reached by both RSC and client graphs hot-updates across edits', async ({
page,
}) => {
await page.goto(f.url())
await waitForHydration(page)
await expect(page.locator('[data-testid="shared-graph-card"]')).toHaveCSS(
'color',
'rgb(128, 0, 128)',
)
await using _ = await expectNoReload(page)
const editor = f.createEditor('src/shared-graph/card.module.css')
editor.edit((s) => s.replaceAll('rgb(128, 0, 128)', 'rgb(255, 0, 0)'))
await expect(page.locator('[data-testid="shared-graph-card"]')).toHaveCSS(
'color',
'rgb(255, 0, 0)',
)
editor.edit((s) => s.replaceAll('rgb(255, 0, 0)', 'rgb(0, 0, 255)'))
await expect(page.locator('[data-testid="shared-graph-card"]')).toHaveCSS(
'color',
'rgb(0, 0, 255)',
)
editor.reset()
await expect(page.locator('[data-testid="shared-graph-card"]')).toHaveCSS(
'color',
'rgb(128, 0, 128)',
)
})
// Covers the "keep JS wrapper in the HMR payload" half: without wrapper
// self-accept, removed rules stay live on <style data-vite-dev-id>
test('removing a rule from the shared css module falls through the cascade', async ({
page,
}) => {
await page.goto(f.url())
await waitForHydration(page)
await expect(page.locator('[data-testid="shared-graph-card"]')).toHaveCSS(
'text-transform',
'uppercase',
)
await using _ = await expectNoReload(page)
const editor = f.createEditor('src/shared-graph/card.module.css')
editor.edit((s) =>
s.replaceAll(
'text-transform: uppercase;',
'/* text-transform: removed */',
),
)
await expect(page.locator('[data-testid="shared-graph-card"]')).toHaveCSS(
'text-transform',
'none',
)
editor.reset()
await expect(page.locator('[data-testid="shared-graph-card"]')).toHaveCSS(
'text-transform',
'uppercase',
)
})
})