Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/reactDom/src/ReactDOM.ml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ let render_to_string ~mode element =
when Html.is_self_closing_tag tag ->
is_root.contents <- false;
Printf.sprintf "<%s%s />" tag (attributes_to_string attributes)
| Lower_case_element { tag; attributes; children }
when String.equal tag "html" ->
is_root.contents <- false;
Printf.sprintf "<!DOCTYPE html><%s%s>%s</%s>" tag
(attributes_to_string attributes)
(children |> List.map render_element |> String.concat "")
tag
| Lower_case_element { tag; attributes; children } ->
is_root.contents <- false;
Printf.sprintf "<%s%s>%s</%s>" tag
Expand Down
7 changes: 7 additions & 0 deletions packages/reactDom/test/test_renderToStaticMarkup.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ let single_empty_tag () =
let div = React.createElement "div" [] [] in
assert_string (ReactDOM.renderToStaticMarkup div) "<div></div>"

let html_doctype () =
let app = React.createElement "html" [] [] in
assert_string
(ReactDOM.renderToStaticMarkup app)
"<!DOCTYPE html><html></html>"

let empty_string_attribute () =
let div = React.createElement "div" [ React.JSX.String ("class", "") ] [] in
assert_string (ReactDOM.renderToStaticMarkup div) "<div class=\"\"></div>"
Expand Down Expand Up @@ -321,6 +327,7 @@ let case title fn = Alcotest_lwt.test_case_sync title `Quick fn
let tests =
( "renderToStaticMarkup",
[
case "html_doctype" html_doctype;
case "single_empty_tag" single_empty_tag;
case "empty_string_attribute" empty_string_attribute;
case "bool_attributes" bool_attributes;
Expand Down