Allow async into client components #310
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR allows Client Components to have Async Components on their props.
To do so, I also had to handle the way we render inside client-props.
Solution
Now, we treat it as a normal Async_component:
client_to_htmlto render the html andrender_element_to_htmlwhile handling the lwt_props, but bothrender_element_to_htmlandclient_to_htmlpushed the resolved html to the context.The solution was to add a flag
skip_push_html. When handling client component props inside, we don't want to push any HTML.| Client_component { import_module; import_name; props; client } -> let context = Fiber.get_context fiber in let lwt_props = Lwt_list.map_p (fun (name, value) -> match (value : React.client_value) with | Element element -> - let%lwt _html, model = render_element_to_html ~fiber element in + let%lwt _html, model = render_element_to_html ~skip_push_html ~fiber element in Lwt.return (name, model) (* ... *) in - let lwt_html = client_to_html ~fiber (client ()) in + let lwt_html = client_to_html ~skip_push_html ~fiber (client ()) in