Skip to content

Commit 67011d0

Browse files
hi-ogawaclaude
andcommitted
test(rsc): add lazy client CSS reproduction
Add reproduction for SSR-ing lazy client component which imports CSS. This is a test case for investigating FOUC (flash of unstyled content) when lazy-loaded client components import CSS files. Ref: wakujs/waku#1911 (comment) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent a599f46 commit 67011d0

5 files changed

Lines changed: 45 additions & 0 deletions

File tree

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

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

1048+
test('lazy client css @js', async ({ page }) => {
1049+
await page.goto(f.url())
1050+
await waitForHydration(page)
1051+
await expect(page.locator('.test-lazy-client-css')).toHaveCSS(
1052+
'color',
1053+
'rgb(255, 165, 0)',
1054+
)
1055+
})
1056+
1057+
testNoJs('lazy client css @nojs', async ({ page }) => {
1058+
await page.goto(f.url())
1059+
await expect(page.locator('.test-lazy-client-css')).toHaveCSS(
1060+
'color',
1061+
'rgb(255, 165, 0)',
1062+
)
1063+
})
1064+
10481065
test('tailwind @js', async ({ page }) => {
10491066
await page.goto(f.url())
10501067
await waitForHydration(page)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use client'
2+
3+
import * as React from 'react'
4+
5+
// React.lazy for SSR-ing lazy client component
6+
const LazyDep = React.lazy(() => import('./lazy-dep'))
7+
8+
export function TestLazyClientCss() {
9+
return (
10+
<div data-testid="test-lazy-client-css">
11+
<React.Suspense fallback={<span>lazy-loading...</span>}>
12+
<LazyDep />
13+
</React.Suspense>
14+
</div>
15+
)
16+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* css imported by lazy client component */
2+
3+
.test-lazy-client-css {
4+
color: rgb(255, 165, 0);
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import './lazy-dep.css'
2+
3+
export default function LazyDep() {
4+
return <span className="test-lazy-client-css">lazy-client-css</span>
5+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { TestHmrSwitchClient } from './hmr-switch/client'
3434
import { TestHmrSwitchServer } from './hmr-switch/server'
3535
import { TestHydrationMismatch } from './hydration-mismatch/server'
3636
import { TestImportMetaGlob } from './import-meta-glob/server'
37+
import { TestLazyClientCss } from './lazy-client-css/client'
3738
import { TestModuleInvalidationServer } from './module-invalidation/server'
3839
import { TestPayloadServer } from './payload/server'
3940
import { TestReactCache } from './react-cache/server'
@@ -101,6 +102,7 @@ export function Root(props: { url: URL }) {
101102
<TestActionStateServer />
102103
<TestModuleInvalidationServer />
103104
<TestBrowserOnly />
105+
<TestLazyClientCss />
104106
<TestUseCache />
105107
<TestReactCache url={props.url} />
106108
<TestCssQueries />

0 commit comments

Comments
 (0)