File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -1078,6 +1078,47 @@ async fn hydrate_empty() {
10781078 assert_eq ! ( result. as_str( ) , r#"<div>after</div><div>after</div>"# ) ;
10791079}
10801080
1081+ #[ wasm_bindgen_test]
1082+ async fn hydrate_flicker ( ) {
1083+ // This components renders the same on the server and client during the first render,
1084+ // but then immediately changes the order of keyed elements in the next render.
1085+ // This should not lead to any hydration failures
1086+ #[ component]
1087+ fn Flickering ( ) -> Html {
1088+ let trigger = use_state ( || false ) ;
1089+ let is_first = !* trigger;
1090+ if is_first {
1091+ trigger. set ( true ) ;
1092+ html ! {
1093+ <>
1094+ <p key="1" >{ "1" } </p>
1095+ <p key="2" >{ "2" } </p>
1096+ </>
1097+ }
1098+ } else {
1099+ html ! {
1100+ <>
1101+ <p key="2" >{ "2" } </p>
1102+ <p key="1" >{ "1" } </p>
1103+ </>
1104+ }
1105+ }
1106+ }
1107+ let s = ServerRenderer :: < Flickering > :: new ( ) . render ( ) . await ;
1108+ let output_element = gloo:: utils:: document ( )
1109+ . query_selector ( "#output" )
1110+ . unwrap ( )
1111+ . unwrap ( ) ;
1112+
1113+ output_element. set_inner_html ( & s) ;
1114+
1115+ Renderer :: < Flickering > :: with_root ( output_element) . hydrate ( ) ;
1116+ sleep ( Duration :: from_millis ( 50 ) ) . await ;
1117+
1118+ let result = obtain_result_by_id ( "output" ) ;
1119+ assert_eq ! ( result. as_str( ) , r#"<p>2</p><p>1</p>"# ) ;
1120+ }
1121+
10811122#[ wasm_bindgen_test]
10821123async fn hydration_with_camelcase_svg_elements ( ) {
10831124 #[ function_component]
You can’t perform that action at this time.
0 commit comments