Skip to content

Commit bc68719

Browse files
forkialfonsogarciacaro
authored andcommitted
Render Attributes with same StringBuilder
1 parent b17e856 commit bc68719

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/Fable.React/Fable.Helpers.ReactServer.fs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -682,8 +682,7 @@ let private renderSVGAttr (attr: SVGAttr): string =
682682
| SVGAttr.Y v -> objAttr "y" v
683683
| SVGAttr.Custom (key, value) -> objAttr (slugKey key) value
684684

685-
let private renderAttrs (attrs: IProp seq) tag =
686-
let html = StringBuilder()
685+
let private renderAttrs (append:string -> unit) (attrs: IProp seq) tag =
687686
let mutable childHtml = None
688687
for attr in attrs do
689688
match attr with
@@ -698,14 +697,14 @@ let private renderAttrs (attrs: IProp seq) tag =
698697
| "textarea", DefaultValue v ->
699698
childHtml <- Some v
700699
| _, _ ->
701-
html.Append(renderHtmlAttr attr) |> ignore
702-
html.Append(" ") |> ignore
700+
append(renderHtmlAttr attr)
701+
append(" ") |> ignore
703702
| :? SVGAttr as attr ->
704-
html.Append(renderSVGAttr attr) |> ignore
705-
html.Append(" ") |> ignore
703+
append(renderSVGAttr attr)
704+
append(" ")
706705
| _ -> ()
707706

708-
html.ToString().Trim(), childHtml
707+
childHtml
709708

710709

711710
let rec private addReactMark htmlNode =
@@ -732,21 +731,25 @@ let renderToString (htmlNode: ReactElement): string =
732731
| HTMLNode.Text str -> html.Append(escapeHtml str)
733732
| HTMLNode.RawText str -> html.Append(str)
734733
| HTMLNode.Node (tag, attrs, children) ->
735-
let attrs, child = renderAttrs attrs tag
734+
append "<"
735+
append tag
736+
737+
let child = renderAttrs append attrs tag
736738

737-
let attrs = if attrs = "" then attrs else " " + attrs
738739
if voidTags.Contains tag then
739-
append "<"; append tag; append attrs; append "/>"
740+
append "/>"
740741
else
741-
append "<"; append tag; append attrs; append ">";
742+
append ">"
742743

743744
match child with
744745
| Some c -> append c
745746
| None ->
746747
for child in children do
747748
render (castHTMLNode child)
748749

749-
append "</"; append tag; append ">"
750+
append "</"
751+
append tag
752+
append ">"
750753
| HTMLNode.List nodes ->
751754
for node in nodes do
752755
render node

0 commit comments

Comments
 (0)