@@ -1240,51 +1240,72 @@ test.describe("RTL", () => {
1240
1240
} ) ;
1241
1241
} ) ;
1242
1242
1243
- test ( "SSR and hydration" , async ( { page } ) => {
1244
- await page . goto ( storyUrl ( "advanced-ssr--default" ) ) ;
1245
-
1246
- const component = await getScrollable ( page ) ;
1247
-
1248
- const first = await getFirstItem ( component ) ;
1249
- const last = await getLastItem ( component ) ;
1250
-
1251
- // check if SSR suceeded
1252
- const itemsSelector = '*[style*="top"]' ;
1253
- const items = component . locator ( itemsSelector ) ;
1254
- const initialLength = await items . count ( ) ;
1255
- expect ( initialLength ) . toBeGreaterThanOrEqual ( 30 ) ;
1256
- expect ( await items . first ( ) . textContent ( ) ) . toEqual ( "0" ) ;
1257
- expect ( await items . last ( ) . textContent ( ) ) . toEqual ( String ( initialLength - 1 ) ) ;
1258
- // check if items have styles for SSR
1259
- expect ( await items . first ( ) . evaluate ( ( e ) => e . style . position ) ) . not . toBe (
1260
- "absolute"
1261
- ) ;
1262
-
1263
- // should not change state with scroll before hydration
1264
- await component . evaluate ( ( e ) => e . scrollTo ( { top : 1000 } ) ) ;
1265
- expect ( initialLength ) . toBe ( await component . locator ( itemsSelector ) . count ( ) ) ;
1266
- await page . waitForTimeout ( 500 ) ;
1267
- await component . evaluate ( ( e ) => e . scrollTo ( { top : 0 } ) ) ;
1268
-
1269
- // hydrate
1270
- await page . getByRole ( "button" , { name : "hydrate" } ) . click ( ) ;
1271
-
1272
- // check if hydration suceeded but state is not changed
1273
- const hydratedItemsLength = await component . locator ( itemsSelector ) . count ( ) ;
1274
- expect ( hydratedItemsLength ) . toBe ( initialLength ) ;
1275
- expect ( ( await getFirstItem ( component ) ) . top ) . toBe ( first . top ) ;
1276
- expect ( ( await getLastItem ( component ) ) . bottom ) . toBe ( last . bottom ) ;
1277
- // check if items do not have styles for SSR
1278
- expect ( await items . first ( ) . evaluate ( ( e ) => e . style . position ) ) . toBe (
1279
- "absolute"
1280
- ) ;
1281
-
1282
- // should change state with scroll after hydration
1283
- await component . evaluate ( ( e ) => e . scrollTo ( { top : 1000 } ) ) ;
1284
- await page . waitForTimeout ( 500 ) ;
1285
- expect ( await component . locator ( itemsSelector ) . count ( ) ) . not . toBe (
1286
- initialLength
1287
- ) ;
1243
+ test . describe ( "SSR and hydration" , ( ) => {
1244
+ test ( "check if hydration works" , async ( { page } ) => {
1245
+ await page . goto ( storyUrl ( "advanced-ssr--default" ) ) ;
1246
+
1247
+ const component = await getScrollable ( page ) ;
1248
+
1249
+ const first = await getFirstItem ( component ) ;
1250
+ const last = await getLastItem ( component ) ;
1251
+
1252
+ // check if SSR suceeded
1253
+ const itemsSelector = '*[style*="top"]' ;
1254
+ const items = component . locator ( itemsSelector ) ;
1255
+ const initialLength = await items . count ( ) ;
1256
+ expect ( initialLength ) . toBeGreaterThanOrEqual ( 30 ) ;
1257
+ expect ( await items . first ( ) . textContent ( ) ) . toEqual ( "0" ) ;
1258
+ expect ( await items . last ( ) . textContent ( ) ) . toEqual ( String ( initialLength - 1 ) ) ;
1259
+ // check if items have styles for SSR
1260
+ expect ( await items . first ( ) . evaluate ( ( e ) => e . style . position ) ) . not . toBe (
1261
+ "absolute"
1262
+ ) ;
1263
+
1264
+ // should not change state with scroll before hydration
1265
+ await component . evaluate ( ( e ) => e . scrollTo ( { top : 1000 } ) ) ;
1266
+ expect ( initialLength ) . toBe ( await component . locator ( itemsSelector ) . count ( ) ) ;
1267
+ await page . waitForTimeout ( 500 ) ;
1268
+ await component . evaluate ( ( e ) => e . scrollTo ( { top : 0 } ) ) ;
1269
+
1270
+ // hydrate
1271
+ await page . getByRole ( "button" , { name : "hydrate" } ) . click ( ) ;
1272
+
1273
+ // check if hydration suceeded but state is not changed
1274
+ const hydratedItemsLength = await component . locator ( itemsSelector ) . count ( ) ;
1275
+ expect ( hydratedItemsLength ) . toBe ( initialLength ) ;
1276
+ expect ( ( await getFirstItem ( component ) ) . top ) . toBe ( first . top ) ;
1277
+ expect ( ( await getLastItem ( component ) ) . bottom ) . toBe ( last . bottom ) ;
1278
+ // check if items do not have styles for SSR
1279
+ expect ( await items . first ( ) . evaluate ( ( e ) => e . style . position ) ) . toBe (
1280
+ "absolute"
1281
+ ) ;
1282
+
1283
+ // should change state with scroll after hydration
1284
+ await component . evaluate ( ( e ) => e . scrollTo ( { top : 1000 } ) ) ;
1285
+ await page . waitForTimeout ( 500 ) ;
1286
+ expect ( await component . locator ( itemsSelector ) . count ( ) ) . not . toBe (
1287
+ initialLength
1288
+ ) ;
1289
+ } ) ;
1290
+
1291
+ test ( "check if smooth scrolling works after hydration" , async ( { page } ) => {
1292
+ await page . goto ( storyUrl ( "advanced-ssr--scroll-to" ) ) ;
1293
+
1294
+ const component = await getScrollable ( page ) ;
1295
+
1296
+ // turn scroll to index with smooth on
1297
+ await page . getByRole ( "checkbox" , { name : "scroll to index" } ) . check ( ) ;
1298
+ await page . getByRole ( "checkbox" , { name : "smooth" } ) . check ( ) ;
1299
+
1300
+ // set scroll index to 100
1301
+ await page . locator ( "input[type=number]" ) . fill ( "100" ) ;
1302
+
1303
+ // hydrate
1304
+ await page . getByRole ( "button" , { name : "hydrate" } ) . click ( ) ;
1305
+
1306
+ await page . waitForTimeout ( 1000 ) ;
1307
+ expect ( ( await getFirstItem ( component ) ) . text ) . toEqual ( "100" ) ;
1308
+ } ) ;
1288
1309
} ) ;
1289
1310
1290
1311
test . describe ( "emulated iOS WebKit" , ( ) => {
0 commit comments