@@ -22,7 +22,7 @@ def SimpleComponentWithHook():
22
22
with pytest .raises (RuntimeError , match = "No life cycle hook is active" ):
23
23
await SimpleComponentWithHook ().render ()
24
24
25
- with idom .Layout (SimpleComponentWithHook ()) as layout :
25
+ async with idom .Layout (SimpleComponentWithHook ()) as layout :
26
26
await layout .render ()
27
27
28
28
@@ -35,7 +35,7 @@ def SimpleStatefulComponent():
35
35
36
36
sse = SimpleStatefulComponent ()
37
37
38
- with idom .Layout (sse ) as layout :
38
+ async with idom .Layout (sse ) as layout :
39
39
patch_1 = await render_json_patch (layout )
40
40
assert patch_1 .path == ""
41
41
assert_same_items (
@@ -75,7 +75,7 @@ def SimpleStatefulComponent():
75
75
76
76
sse = SimpleStatefulComponent ()
77
77
78
- with idom .Layout (sse ) as layout :
78
+ async with idom .Layout (sse ) as layout :
79
79
await layout .render ()
80
80
await layout .render ()
81
81
await layout .render ()
@@ -108,7 +108,7 @@ def Inner():
108
108
state , set_inner_state .current = idom .use_state (make_default )
109
109
return idom .html .div (state )
110
110
111
- with idom .Layout (Outer ()) as layout :
111
+ async with idom .Layout (Outer ()) as layout :
112
112
await layout .render ()
113
113
114
114
assert constructor_call_count .current == 1
@@ -141,7 +141,7 @@ def Counter():
141
141
count .current , set_count .current = idom .hooks .use_state (0 )
142
142
return idom .html .div (count .current )
143
143
144
- with idom .Layout (Counter ()) as layout :
144
+ async with idom .Layout (Counter ()) as layout :
145
145
await layout .render ()
146
146
147
147
for i in range (4 ):
@@ -308,7 +308,7 @@ def CheckNoEffectYet():
308
308
effect_triggers_after_final_render .current = not effect_triggered .current
309
309
return idom .html .div ()
310
310
311
- with idom .Layout (OuterComponent ()) as layout :
311
+ async with idom .Layout (OuterComponent ()) as layout :
312
312
await layout .render ()
313
313
314
314
assert effect_triggered .current
@@ -336,7 +336,7 @@ def cleanup():
336
336
337
337
return idom .html .div ()
338
338
339
- with idom .Layout (ComponentWithEffect ()) as layout :
339
+ async with idom .Layout (ComponentWithEffect ()) as layout :
340
340
await layout .render ()
341
341
342
342
assert not cleanup_triggered .current
@@ -375,7 +375,7 @@ def cleanup():
375
375
376
376
return idom .html .div ()
377
377
378
- with idom .Layout (OuterComponent ()) as layout :
378
+ async with idom .Layout (OuterComponent ()) as layout :
379
379
await layout .render ()
380
380
381
381
assert not cleanup_triggered .current
@@ -406,7 +406,7 @@ def effect():
406
406
407
407
return idom .html .div ()
408
408
409
- with idom .Layout (ComponentWithMemoizedEffect ()) as layout :
409
+ async with idom .Layout (ComponentWithMemoizedEffect ()) as layout :
410
410
await layout .render ()
411
411
412
412
assert effect_run_count .current == 1
@@ -449,7 +449,7 @@ def cleanup():
449
449
450
450
return idom .html .div ()
451
451
452
- with idom .Layout (ComponentWithEffect ()) as layout :
452
+ async with idom .Layout (ComponentWithEffect ()) as layout :
453
453
await layout .render ()
454
454
455
455
assert cleanup_trigger_count .current == 0
@@ -476,7 +476,7 @@ async def effect():
476
476
477
477
return idom .html .div ()
478
478
479
- with idom .Layout (ComponentWithAsyncEffect ()) as layout :
479
+ async with idom .Layout (ComponentWithAsyncEffect ()) as layout :
480
480
await layout .render ()
481
481
await asyncio .wait_for (effect_ran .wait (), 1 )
482
482
@@ -496,7 +496,7 @@ async def effect():
496
496
497
497
return idom .html .div ()
498
498
499
- with idom .Layout (ComponentWithAsyncEffect ()) as layout :
499
+ async with idom .Layout (ComponentWithAsyncEffect ()) as layout :
500
500
await layout .render ()
501
501
502
502
component_hook .latest .schedule_render ()
@@ -527,7 +527,7 @@ async def effect():
527
527
528
528
return idom .html .div ()
529
529
530
- with idom .Layout (ComponentWithLongWaitingEffect ()) as layout :
530
+ async with idom .Layout (ComponentWithLongWaitingEffect ()) as layout :
531
531
await layout .render ()
532
532
533
533
await effect_ran .wait ()
@@ -554,7 +554,7 @@ def bad_effect():
554
554
return idom .html .div ()
555
555
556
556
with assert_idom_logged (match_message = r"Layout post-render effect .* failed" ):
557
- with idom .Layout (ComponentWithEffect ()) as layout :
557
+ async with idom .Layout (ComponentWithEffect ()) as layout :
558
558
await layout .render () # no error
559
559
560
560
@@ -575,7 +575,7 @@ def bad_cleanup():
575
575
return idom .html .div ()
576
576
577
577
with assert_idom_logged (match_error = r"Layout post-render effect .* failed" ):
578
- with idom .Layout (ComponentWithEffect ()) as layout :
578
+ async with idom .Layout (ComponentWithEffect ()) as layout :
579
579
await layout .render ()
580
580
component_hook .latest .schedule_render ()
581
581
await layout .render () # no error
@@ -604,7 +604,7 @@ def bad_cleanup():
604
604
match_message = r"Pre-unmount effect .*? failed" ,
605
605
error_type = ValueError ,
606
606
):
607
- with idom .Layout (OuterComponent ()) as layout :
607
+ async with idom .Layout (OuterComponent ()) as layout :
608
608
await layout .render ()
609
609
set_key .current ("second" )
610
610
await layout .render () # no error
@@ -629,7 +629,7 @@ def Counter(initial_count):
629
629
)
630
630
return idom .html .div ()
631
631
632
- with idom .Layout (Counter (0 )) as layout :
632
+ async with idom .Layout (Counter (0 )) as layout :
633
633
await layout .render ()
634
634
635
635
assert saved_count .current == 0
@@ -659,7 +659,7 @@ def ComponentWithUseReduce():
659
659
saved_dispatchers .append (idom .hooks .use_reducer (reducer , 0 )[1 ])
660
660
return idom .html .div ()
661
661
662
- with idom .Layout (ComponentWithUseReduce ()) as layout :
662
+ async with idom .Layout (ComponentWithUseReduce ()) as layout :
663
663
for _ in range (3 ):
664
664
await layout .render ()
665
665
saved_dispatchers [- 1 ]("increment" )
@@ -679,7 +679,7 @@ def ComponentWithRef():
679
679
used_callbacks .append (idom .hooks .use_callback (lambda : None ))
680
680
return idom .html .div ()
681
681
682
- with idom .Layout (ComponentWithRef ()) as layout :
682
+ async with idom .Layout (ComponentWithRef ()) as layout :
683
683
await layout .render ()
684
684
component_hook .latest .schedule_render ()
685
685
await layout .render ()
@@ -705,7 +705,7 @@ def cb():
705
705
used_callbacks .append (cb )
706
706
return idom .html .div ()
707
707
708
- with idom .Layout (ComponentWithRef ()) as layout :
708
+ async with idom .Layout (ComponentWithRef ()) as layout :
709
709
await layout .render ()
710
710
set_state_hook .current (1 )
711
711
await layout .render ()
@@ -733,7 +733,7 @@ def ComponentWithMemo():
733
733
used_values .append (value )
734
734
return idom .html .div ()
735
735
736
- with idom .Layout (ComponentWithMemo ()) as layout :
736
+ async with idom .Layout (ComponentWithMemo ()) as layout :
737
737
await layout .render ()
738
738
set_state_hook .current (1 )
739
739
await layout .render ()
@@ -758,7 +758,7 @@ def ComponentWithMemo():
758
758
used_values .append (value )
759
759
return idom .html .div ()
760
760
761
- with idom .Layout (ComponentWithMemo ()) as layout :
761
+ async with idom .Layout (ComponentWithMemo ()) as layout :
762
762
await layout .render ()
763
763
component_hook .latest .schedule_render ()
764
764
await layout .render ()
@@ -785,7 +785,7 @@ def ComponentWithMemo():
785
785
used_values .append (value )
786
786
return idom .html .div ()
787
787
788
- with idom .Layout (ComponentWithMemo ()) as layout :
788
+ async with idom .Layout (ComponentWithMemo ()) as layout :
789
789
await layout .render ()
790
790
component_hook .latest .schedule_render ()
791
791
deps_used_in_memo .current = None
@@ -810,7 +810,7 @@ def ComponentWithMemo():
810
810
used_values .append (value )
811
811
return idom .html .div ()
812
812
813
- with idom .Layout (ComponentWithMemo ()) as layout :
813
+ async with idom .Layout (ComponentWithMemo ()) as layout :
814
814
await layout .render ()
815
815
component_hook .latest .schedule_render ()
816
816
await layout .render ()
@@ -830,7 +830,7 @@ def ComponentWithRef():
830
830
used_refs .append (idom .hooks .use_ref (1 ))
831
831
return idom .html .div ()
832
832
833
- with idom .Layout (ComponentWithRef ()) as layout :
833
+ async with idom .Layout (ComponentWithRef ()) as layout :
834
834
await layout .render ()
835
835
component_hook .latest .schedule_render ()
836
836
await layout .render ()
@@ -865,7 +865,7 @@ def some_effect_that_uses_count():
865
865
866
866
return idom .html .div ()
867
867
868
- with idom .Layout (CounterWithEffect ()) as layout :
868
+ async with idom .Layout (CounterWithEffect ()) as layout :
869
869
await layout .render ()
870
870
await did_effect .wait ()
871
871
did_effect .clear ()
@@ -893,7 +893,7 @@ def some_memo_func_that_uses_count():
893
893
894
894
return idom .html .div ()
895
895
896
- with idom .Layout (CounterWithEffect ()) as layout :
896
+ async with idom .Layout (CounterWithEffect ()) as layout :
897
897
await layout .render ()
898
898
await did_memo .wait ()
899
899
did_memo .clear ()
@@ -918,7 +918,7 @@ def ComponentUsesContext():
918
918
value .current = idom .use_context (Context )
919
919
return html .div ()
920
920
921
- with idom .Layout (ComponentProvidesContext ()) as layout :
921
+ async with idom .Layout (ComponentProvidesContext ()) as layout :
922
922
await layout .render ()
923
923
assert value .current == "something"
924
924
@@ -927,7 +927,7 @@ def ComponentUsesContext():
927
927
value .current = idom .use_context (Context )
928
928
return html .div ()
929
929
930
- with idom .Layout (ComponentUsesContext ()) as layout :
930
+ async with idom .Layout (ComponentUsesContext ()) as layout :
931
931
await layout .render ()
932
932
assert value .current == "something"
933
933
@@ -958,7 +958,7 @@ def ComponentInContext():
958
958
render_count .current += 1
959
959
return html .div ()
960
960
961
- with idom .Layout (ComponentProvidesContext ()) as layout :
961
+ async with idom .Layout (ComponentProvidesContext ()) as layout :
962
962
await layout .render ()
963
963
assert render_count .current == 1
964
964
@@ -995,7 +995,7 @@ def MemoizedComponentUsesContext():
995
995
render_count .current += 1
996
996
return html .div ()
997
997
998
- with idom .Layout (ComponentProvidesContext ()) as layout :
998
+ async with idom .Layout (ComponentProvidesContext ()) as layout :
999
999
await layout .render ()
1000
1000
assert render_count .current == 1
1001
1001
assert value .current == 0
@@ -1041,7 +1041,7 @@ def Inner():
1041
1041
inner_render_count .current += 1
1042
1042
return html .div ()
1043
1043
1044
- with idom .Layout (Root ()) as layout :
1044
+ async with idom .Layout (Root ()) as layout :
1045
1045
await layout .render ()
1046
1046
assert outer_render_count .current == 1
1047
1047
assert inner_render_count .current == 1
@@ -1097,7 +1097,7 @@ def Right():
1097
1097
right_used_value .current = idom .use_context (RightContext )
1098
1098
return idom .html .div ()
1099
1099
1100
- with idom .Layout (Root ()) as layout :
1100
+ async with idom .Layout (Root ()) as layout :
1101
1101
await layout .render ()
1102
1102
assert left_render_count .current == 1
1103
1103
assert right_render_count .current == 1
@@ -1142,7 +1142,7 @@ def bad_effect():
1142
1142
error_type = ValueError ,
1143
1143
match_error = "The error message" ,
1144
1144
):
1145
- with idom .Layout (ComponentWithEffect ()) as layout :
1145
+ async with idom .Layout (ComponentWithEffect ()) as layout :
1146
1146
await layout .render ()
1147
1147
component_hook .latest .schedule_render ()
1148
1148
await layout .render () # no error
@@ -1159,7 +1159,7 @@ def SetStateDuringRender():
1159
1159
set_state (state + 1 )
1160
1160
return html .div (state )
1161
1161
1162
- with Layout (SetStateDuringRender ()) as layout :
1162
+ async with Layout (SetStateDuringRender ()) as layout :
1163
1163
await layout .render ()
1164
1164
assert render_count .current == 1
1165
1165
await layout .render ()
0 commit comments