Skip to content

Commit caf9bf1

Browse files
hi-ogawaclaude
andauthored
test(rsc): add lazy client CSS reproduction (#1056)
Co-authored-by: Claude Opus 4.5 <[email protected]>
1 parent a1f1e99 commit caf9bf1

File tree

11 files changed

+167
-0
lines changed

11 files changed

+167
-0
lines changed

packages/plugin-rsc/e2e/basic.test.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,85 @@ function defineTest(f: Fixture) {
10451045
)
10461046
})
10471047

1048+
// TODO: lazy component CSS is not yet fully supported
1049+
// https://github.com/vitejs/vite-plugin-react/issues/1057
1050+
1051+
// Case 1: client -> lazy client -> CSS
1052+
test('lazy css client to client @js', async ({ page }) => {
1053+
await page.goto(f.url())
1054+
await waitForHydration(page)
1055+
// CSS is loaded after hydration via JS
1056+
await expect(page.locator('.test-lazy-css-client-to-client')).toHaveCSS(
1057+
'color',
1058+
'rgb(255, 165, 0)',
1059+
)
1060+
})
1061+
1062+
testNoJs('lazy css client to client @nojs', async ({ page }) => {
1063+
await page.goto(f.url())
1064+
// component is rendered correctly in SSR
1065+
await expect(page.locator('.test-lazy-css-client-to-client')).toHaveText(
1066+
'lazy-css-client-to-client',
1067+
)
1068+
// but CSS is not included in SSR (FOUC)
1069+
await expect(page.locator('.test-lazy-css-client-to-client')).toHaveCSS(
1070+
'color',
1071+
'rgb(0, 0, 0)',
1072+
)
1073+
})
1074+
1075+
// Case 2: server -> lazy client with CSS
1076+
test('lazy css server to client @js', async ({ page }) => {
1077+
await page.goto(f.url())
1078+
await waitForHydration(page)
1079+
await expect(page.locator('.test-lazy-css-server-to-client')).toHaveCSS(
1080+
'color',
1081+
'rgb(255, 165, 0)',
1082+
)
1083+
})
1084+
1085+
testNoJs('lazy css server to client @nojs', async ({ page }) => {
1086+
await page.goto(f.url())
1087+
await expect(page.locator('.test-lazy-css-server-to-client')).toHaveText(
1088+
'lazy-css-server-to-client',
1089+
)
1090+
// CSS is included in SSR
1091+
await expect(page.locator('.test-lazy-css-server-to-client')).toHaveCSS(
1092+
'color',
1093+
'rgb(255, 165, 0)',
1094+
)
1095+
})
1096+
1097+
// Case 3: server -> lazy server with CSS
1098+
test('lazy css server to server @js', async ({ page }) => {
1099+
await page.goto(f.url())
1100+
await waitForHydration(page)
1101+
await expect(page.locator('.test-lazy-css-server-to-server')).toHaveText(
1102+
'lazy-css-server-to-server',
1103+
)
1104+
await expect(page.locator('.test-lazy-css-server-to-server')).toHaveCSS(
1105+
'color',
1106+
'rgb(255, 165, 0)',
1107+
)
1108+
})
1109+
1110+
// suspense can fallback due to `viteRsc.loadCss` wrapper
1111+
// but streamed lazy server component html comes with css, so no FOUC.
1112+
// TODO: skipped for now since not reliable
1113+
testNoJs('lazy css server to server @nojs', async ({ page }) => {
1114+
await page.goto(f.url())
1115+
// await expect(page.locator('.test-lazy-css-server-to-server')).toHaveText(
1116+
// 'loading',
1117+
// )
1118+
// await expect(page.locator('.test-lazy-css-server-to-server')).toHaveText(
1119+
// 'lazy-css-server-to-server',
1120+
// )
1121+
// await expect(page.locator('.test-lazy-css-server-to-server')).toHaveCSS(
1122+
// 'color',
1123+
// 'rgb(255, 165, 0)',
1124+
// )
1125+
})
1126+
10481127
test('tailwind @js', async ({ page }) => {
10491128
await page.goto(f.url())
10501129
await waitForHydration(page)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.test-lazy-css-client-to-client {
2+
color: rgb(255, 165, 0);
3+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import './client-to-client-child.css'
2+
3+
export default function ClientToClientChild() {
4+
return (
5+
<span className="test-lazy-css-client-to-client">
6+
lazy-css-client-to-client
7+
</span>
8+
)
9+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use client'
2+
3+
// Case 1: client component -> lazy client component -> CSS
4+
import * as React from 'react'
5+
6+
const LazyChild = React.lazy(() => import('./client-to-client-child'))
7+
8+
export function TestLazyCssClientToClient() {
9+
return (
10+
<div data-testid="test-lazy-css-client-to-client">
11+
<React.Suspense fallback={<span>loading...</span>}>
12+
<LazyChild />
13+
</React.Suspense>
14+
</div>
15+
)
16+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.test-lazy-css-server-to-client {
2+
color: rgb(255, 165, 0);
3+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use client'
2+
3+
import './server-to-client-child.css'
4+
5+
export default function ServerToClientChild() {
6+
return (
7+
<span className="test-lazy-css-server-to-client">
8+
lazy-css-server-to-client
9+
</span>
10+
)
11+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Case 2: server component -> lazy client component with CSS
2+
import * as React from 'react'
3+
4+
const LazyChild = React.lazy(() => import('./server-to-client-child'))
5+
6+
export function TestLazyCssServerToClient() {
7+
return (
8+
<div data-testid="test-lazy-css-server-to-client">
9+
<React.Suspense fallback={<span>loading...</span>}>
10+
<LazyChild />
11+
</React.Suspense>
12+
</div>
13+
)
14+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.test-lazy-css-server-to-server {
2+
color: rgb(255, 165, 0);
3+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import './server-to-server-child.css'
2+
3+
export default function ServerToServerChild() {
4+
return (
5+
<span className="test-lazy-css-server-to-server">
6+
lazy-css-server-to-server
7+
</span>
8+
)
9+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Case 3: server component -> lazy server component with CSS
2+
import * as React from 'react'
3+
4+
const LazyChild = React.lazy(() => import('./server-to-server-child'))
5+
6+
export function TestLazyCssServerToServer() {
7+
return (
8+
<div data-testid="test-lazy-css-server-to-server">
9+
<React.Suspense fallback={<span>loading...</span>}>
10+
<LazyChild />
11+
</React.Suspense>
12+
</div>
13+
)
14+
}

0 commit comments

Comments
 (0)