From 74de672e99002c315f42070d6f76aa1a2da52051 Mon Sep 17 00:00:00 2001 From: David Sancho Moreno Date: Wed, 2 Aug 2023 16:42:56 +0200 Subject: [PATCH] Wrap in Lwt.async --- packages/react/src/react.ml | 2 +- packages/reactDom/src/reactDOM.ml | 27 ++++++++++++++------------- server-reason-react.opam | 2 +- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/packages/react/src/react.ml b/packages/react/src/react.ml index f94407a06..fb353657c 100644 --- a/packages/react/src/react.ml +++ b/packages/react/src/react.ml @@ -206,7 +206,7 @@ let createContext (initial_value : 'a) : 'a context = module Suspense = struct let make ~fallback ~children = Suspense { fallback; children } -end +end [@react.component] (* let memo f : 'props * 'props -> bool = f let memoCustomCompareProps f _compare : 'props * 'props -> bool = f *) diff --git a/packages/reactDom/src/reactDOM.ml b/packages/reactDom/src/reactDOM.ml index eeff04b31..fab8599d9 100644 --- a/packages/reactDom/src/reactDOM.ml +++ b/packages/reactDom/src/reactDOM.ml @@ -208,19 +208,20 @@ let render_to_stream ~context_state element = let current_boundary_id = context_state.boundary_id in let current_suspense_id = context_state.suspense_id in (* Wait for promise to resolve *) - Lwt.map - (fun _ -> - context_state.push - (render_resolved_element ~id:current_suspense_id children); - context_state.push inline_complete_boundary_script; - context_state.push - (render_inline_rc_replacement - [ (current_boundary_id, current_suspense_id) ]); - context_state.waiting <- context_state.waiting - 1; - context_state.suspense_id <- context_state.suspense_id + 1; - if context_state.waiting = 0 then context_state.close () else ()) - promise - |> Lwt.ignore_result; + Lwt.async (fun () -> + Lwt.map + (fun _ -> + context_state.push + (render_resolved_element ~id:current_suspense_id children); + context_state.push inline_complete_boundary_script; + context_state.push + (render_inline_rc_replacement + [ (current_boundary_id, current_suspense_id) ]); + context_state.waiting <- context_state.waiting - 1; + context_state.suspense_id <- context_state.suspense_id + 1; + if context_state.waiting = 0 then context_state.close () + else ()) + promise); context_state.boundary_id <- context_state.boundary_id + 1; (* Render the fallback state *) Printf.sprintf "%s" diff --git a/server-reason-react.opam b/server-reason-react.opam index 902c5ee8f..f59dafebe 100644 --- a/server-reason-react.opam +++ b/server-reason-react.opam @@ -14,8 +14,8 @@ depends: [ "reason" {>= "3.8.1"} "pcre" {>= "7.4.0"} "promise" {>= "1.1.2"} - "alcotest" {with-test} "lwt" {>= "5.6.0"} + "alcotest" {with-test} "fmt" {with-test} "ocamlformat" {= "0.21.0" & with-test} "ocaml-lsp-server" {with-test}