Skip to content

Commit 11297f7

Browse files
hi-ogawaclaude
andcommitted
test(rsc): add more lazy CSS test cases
Add test cases to document current behavior: Case 1: client -> lazy client -> CSS (two steps) - @js: CSS loads after hydration (FOUC) - @nojs: CSS not applied Case 2: server -> lazy client with CSS (one step) - @js: works - @nojs: works (CSS included in SSR) Case 3: server -> lazy server with CSS - @js: CSS never loads - @nojs: CSS not applied Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 19541a3 commit 11297f7

7 files changed

Lines changed: 110 additions & 0 deletions

File tree

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,8 @@ function defineTest(f: Fixture) {
10471047

10481048
// TODO: lazy client component CSS is not yet supported
10491049
// https://github.com/wakujs/waku/issues/1911
1050+
1051+
// Case 1: client component -> lazy client component -> CSS (two steps)
10501052
test('lazy client css @js', async ({ page }) => {
10511053
await page.goto(f.url())
10521054
await waitForHydration(page)
@@ -1070,6 +1072,56 @@ function defineTest(f: Fixture) {
10701072
)
10711073
})
10721074

1075+
// Case 2: server component -> lazy client component with CSS (one step)
1076+
// This works because the client component CSS is tracked
1077+
test('lazy client css direct @js', async ({ page }) => {
1078+
await page.goto(f.url())
1079+
await waitForHydration(page)
1080+
await expect(page.locator('.test-lazy-client-css-direct')).toHaveCSS(
1081+
'color',
1082+
'rgb(255, 165, 0)',
1083+
)
1084+
})
1085+
1086+
testNoJs('lazy client css direct @nojs', async ({ page }) => {
1087+
await page.goto(f.url())
1088+
await expect(page.locator('.test-lazy-client-css-direct')).toHaveText(
1089+
'lazy-client-css-direct',
1090+
)
1091+
// CSS is included in SSR for direct lazy client components
1092+
await expect(page.locator('.test-lazy-client-css-direct')).toHaveCSS(
1093+
'color',
1094+
'rgb(255, 165, 0)',
1095+
)
1096+
})
1097+
1098+
// Case 3: server component -> lazy server component with CSS
1099+
// CSS from lazy server components is not supported
1100+
test('lazy server css @js', async ({ page }) => {
1101+
await page.goto(f.url())
1102+
await waitForHydration(page)
1103+
await expect(page.locator('.test-lazy-server-css')).toHaveText(
1104+
'lazy-server-css',
1105+
)
1106+
// CSS is never loaded (not even via JS)
1107+
await expect(page.locator('.test-lazy-server-css')).toHaveCSS(
1108+
'color',
1109+
'rgb(0, 0, 0)',
1110+
)
1111+
})
1112+
1113+
testNoJs('lazy server css @nojs', async ({ page }) => {
1114+
await page.goto(f.url())
1115+
await expect(page.locator('.test-lazy-server-css')).toHaveText(
1116+
'lazy-server-css',
1117+
)
1118+
// CSS from lazy server component is not included in SSR
1119+
await expect(page.locator('.test-lazy-server-css')).toHaveCSS(
1120+
'color',
1121+
'rgb(0, 0, 0)',
1122+
)
1123+
})
1124+
10731125
test('tailwind @js', async ({ page }) => {
10741126
await page.goto(f.url())
10751127
await waitForHydration(page)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.test-lazy-client-css-direct {
2+
color: rgb(255, 165, 0);
3+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use client'
2+
3+
// Direct case: lazy client component with CSS (one step)
4+
import './client-direct.css'
5+
6+
export function TestLazyClientCssDirect() {
7+
return (
8+
<span className="test-lazy-client-css-direct">lazy-client-css-direct</span>
9+
)
10+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.test-lazy-server-css {
2+
color: rgb(255, 165, 0);
3+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import './lazy-server-dep.css'
2+
3+
export default function LazyServerDep() {
4+
return <span className="test-lazy-server-css">lazy-server-css</span>
5+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import * as React from 'react'
2+
3+
// Server component lazy-loading a client component with CSS directly
4+
const LazyClientDirect = React.lazy(() =>
5+
import('./client-direct').then((m) => ({
6+
default: m.TestLazyClientCssDirect,
7+
})),
8+
)
9+
10+
// Server component lazy-loading a server component with CSS
11+
const LazyServerDep = React.lazy(() => import('./lazy-server-dep'))
12+
13+
export function TestLazyClientCssServer() {
14+
return (
15+
<div data-testid="test-lazy-client-css-server">
16+
<React.Suspense fallback={<span>lazy-loading...</span>}>
17+
<LazyClientDirect />
18+
</React.Suspense>
19+
</div>
20+
)
21+
}
22+
23+
export function TestLazyServerCss() {
24+
return (
25+
<div data-testid="test-lazy-server-css">
26+
<React.Suspense fallback={<span>lazy-loading...</span>}>
27+
<LazyServerDep />
28+
</React.Suspense>
29+
</div>
30+
)
31+
}

packages/plugin-rsc/examples/basic/src/routes/root.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ import { TestHmrSwitchServer } from './hmr-switch/server'
3535
import { TestHydrationMismatch } from './hydration-mismatch/server'
3636
import { TestImportMetaGlob } from './import-meta-glob/server'
3737
import { TestLazyClientCss } from './lazy-client-css/client'
38+
import {
39+
TestLazyClientCssServer,
40+
TestLazyServerCss,
41+
} from './lazy-client-css/server'
3842
import { TestModuleInvalidationServer } from './module-invalidation/server'
3943
import { TestPayloadServer } from './payload/server'
4044
import { TestReactCache } from './react-cache/server'
@@ -103,6 +107,8 @@ export function Root(props: { url: URL }) {
103107
<TestModuleInvalidationServer />
104108
<TestBrowserOnly />
105109
<TestLazyClientCss />
110+
<TestLazyClientCssServer />
111+
<TestLazyServerCss />
106112
<TestUseCache />
107113
<TestReactCache url={props.url} />
108114
<TestCssQueries />

0 commit comments

Comments
 (0)