Skip to content

Commit 018c399

Browse files
committed
feat: allow async in client props
1 parent 4ecfe9d commit 018c399

File tree

1 file changed

+44
-10
lines changed

1 file changed

+44
-10
lines changed

packages/reactDom/test/test_RSC_html.ml

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -653,9 +653,17 @@ let client_component_with_async_component () =
653653
'>window.srr_stream.push()</script>"
654654
[ "<script data-payload='1:I[\"./client.js\",[],\"Client\"]\n'>window.srr_stream.push()</script>" ]
655655

656-
let client_component_with_suspense_async_component () =
657-
let async_suspense () =
658-
React.Suspense.make ~fallback:(React.string "Loading...") ~children:(await_tick ~ms:1 "Async Component") ()
656+
(* This test ensures that we don't push multiple scripts for the Suspense component *)
657+
let client_component_with_nested_suspense_client_component () =
658+
let async_suspense ~children =
659+
React.Suspense.make ~fallback:(React.string "Loading...")
660+
~children:
661+
(React.Async_component
662+
( "async_suspense",
663+
fun () ->
664+
let%lwt () = sleep ~ms:10 in
665+
Lwt.return children ))
666+
()
659667
in
660668
let client_component ~children =
661669
React.Client_component
@@ -666,16 +674,42 @@ let client_component_with_suspense_async_component () =
666674
client = children;
667675
}
668676
in
669-
let app () = client_component ~children:(async_suspense ()) in
670-
assert_html (app ())
677+
assert_html
678+
(client_component
679+
~children:
680+
(React.array
681+
[|
682+
React.string "Root";
683+
async_suspense
684+
~children:
685+
(React.array
686+
[|
687+
React.string "Level 2";
688+
client_component
689+
~children:
690+
(React.array
691+
[|
692+
React.string "Level 3";
693+
client_component ~children:(async_suspense ~children:(React.string "Level 4"));
694+
|]);
695+
|]);
696+
|]))
671697
~shell:
672-
"<!--$?--><template id=\"B:1\"></template>Loading...<!--/$--><script \
673-
data-payload='0:[\"$\",\"$3\",null,{\"children\":[\"$\",\"$Sreact.suspense\",null,{\"fallback\":\"Loading...\",\"children\":\"$L2\"},null,[],{}]},null,[],{}]\n\
698+
"Root<!--$?--><template id=\"B:1\"></template>Loading...<!--/$--><script \
699+
data-payload='0:[\"$\",\"$3\",null,{\"children\":[\"Root\",[\"$\",\"$Sreact.suspense\",null,{\"fallback\":\"Loading...\",\"children\":\"$L2\"},null,[],{}]]},null,[],{}]\n\
674700
'>window.srr_stream.push()</script>"
675701
[
676702
"<script data-payload='3:I[\"./client.js\",[],\"Client\"]\n'>window.srr_stream.push()</script>";
677-
"<div hidden=\"true\" id=\"S:1\">Async Component</div>\n<script>$RC('B:1', 'S:1')</script>";
678-
"<script data-payload='2:\"Async Component\"\n'>window.srr_stream.push()</script>";
703+
"<div hidden=\"true\" id=\"S:1\">Level 2<!-- -->Level 3<!--$?--><template \
704+
id=\"B:4\"></template>Loading...<!--/$--></div>\n\
705+
<script>$RC('B:1', 'S:1')</script>";
706+
"<script data-payload='8:I[\"./client.js\",[],\"Client\"]\n'>window.srr_stream.push()</script>";
707+
"<script data-payload='9:I[\"./client.js\",[],\"Client\"]\n'>window.srr_stream.push()</script>";
708+
"<script data-payload='2:[\"Level 2\",[\"$\",\"$9\",null,{\"children\":[\"Level \
709+
3\",[\"$\",\"$8\",null,{\"children\":[\"$\",\"$Sreact.suspense\",null,{\"fallback\":\"Loading...\",\"children\":\"$L7\"},null,[],{}]},null,[],{}]]},null,[],{}]]\n\
710+
'>window.srr_stream.push()</script>";
711+
"<div hidden=\"true\" id=\"S:4\">Level 4</div>\n<script>$RC('B:4', 'S:4')</script>";
712+
"<script data-payload='7:\"Level 4\"\n'>window.srr_stream.push()</script>";
679713
]
680714

681715
let tests =
@@ -701,7 +735,7 @@ let tests =
701735
test "suspense_in_a_list_with_error" suspense_in_a_list_with_error;
702736
test "server_function_as_action" server_function_as_action;
703737
test "client_component_with_async_component" client_component_with_async_component;
704-
test "client_component_with_suspense_async_component" client_component_with_suspense_async_component;
738+
test "client_component_with_nested_suspense_client_component" client_component_with_nested_suspense_client_component;
705739
(* test "nested_context" nested_context; *)
706740
(* test "client_component_with_suspense_prop" client_component_with_suspense_prop; *)
707741
(* test "page_with_resources" page_with_resources;

0 commit comments

Comments
 (0)