From 7bf4fc9183d99b9ed4cd9236dafccc372a588603 Mon Sep 17 00:00:00 2001 From: Pedro Lisboa <35539594+pedrobslisboa@users.noreply.github.com> Date: Thu, 11 Apr 2024 11:33:30 -0300 Subject: [PATCH] Remove data-reactroot attr from ReactDom render_element (#129) --- packages/reactDom/src/ReactDOM.ml | 11 ++--------- packages/reactDom/test/test_renderToString.ml | 12 ++++-------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/packages/reactDom/src/ReactDOM.ml b/packages/reactDom/src/ReactDOM.ml index e0f029c8b..91dff2365 100644 --- a/packages/reactDom/src/ReactDOM.ml +++ b/packages/reactDom/src/ReactDOM.ml @@ -60,9 +60,6 @@ let attributes_to_string attrs = | [] -> "" | rest -> " " ^ (rest |> String.concat " " |> String.trim) -let react_root_attr_name = "data-reactroot" -let data_react_root_attr = Printf.sprintf " %s=\"\"" react_root_attr_name - type mode = String | Markup let render_to_string ~mode element = @@ -74,9 +71,6 @@ let render_to_string ~mode element = between text nodes *) let previous_was_text_node = ref false in let rec render_element element = - let root_attribute = - match is_root.contents with true -> data_react_root_attr | false -> "" - in match element with | Empty -> "" | Provider children -> render_element children @@ -88,11 +82,10 @@ let render_to_string ~mode element = | Lower_case_element { tag; attributes; _ } when Html.is_self_closing_tag tag -> is_root.contents <- false; - Printf.sprintf "<%s%s%s />" tag root_attribute - (attributes_to_string attributes) + Printf.sprintf "<%s%s />" tag (attributes_to_string attributes) | Lower_case_element { tag; attributes; children } -> is_root.contents <- false; - Printf.sprintf "<%s%s%s>%s" tag root_attribute + Printf.sprintf "<%s%s>%s" tag (attributes_to_string attributes) (children |> List.map render_element |> String.concat "") tag diff --git a/packages/reactDom/test/test_renderToString.ml b/packages/reactDom/test/test_renderToString.ml index 65056a2e1..d277195bd 100644 --- a/packages/reactDom/test/test_renderToString.ml +++ b/packages/reactDom/test/test_renderToString.ml @@ -3,22 +3,18 @@ let assert_string left right = let react_root_one_element () = let div = React.createElement "div" [] [] in - assert_string (ReactDOM.renderToString div) "
" + assert_string (ReactDOM.renderToString div) "
" let react_root_two_elements () = let div = React.createElement "div" [] [ React.createElement "span" [] [] ] in - assert_string - (ReactDOM.renderToString div) - "
" + assert_string (ReactDOM.renderToString div) "
" let text_single_node () = let div = React.createElement "div" [] [ React.createElement "span" [] [ React.string "Hello" ] ] in - assert_string - (ReactDOM.renderToString div) - "
Hello
" + assert_string (ReactDOM.renderToString div) "
Hello
" let consecutives_text_nodes () = let div = @@ -30,7 +26,7 @@ let consecutives_text_nodes () = in assert_string (ReactDOM.renderToString div) - "
HelloHello
" + "
HelloHello
" let case title fn = Alcotest_lwt.test_case_sync title `Quick fn