@@ -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 )
0 commit comments