diff --git a/.changeset/twelve-kiwis-tap.md b/.changeset/twelve-kiwis-tap.md new file mode 100644 index 00000000..fa6322bb --- /dev/null +++ b/.changeset/twelve-kiwis-tap.md @@ -0,0 +1,5 @@ +--- +'preact-render-to-string': patch +--- + +Optimize perf by using smarter string builder diff --git a/src/index.js b/src/index.js index 6c2b24aa..f5024e40 100644 --- a/src/index.js +++ b/src/index.js @@ -85,15 +85,10 @@ function _renderToString(vnode, context, opts, inner, isSvgMode, selectValue) { if (Array.isArray(vnode)) { let rendered = ''; for (let i = 0; i < vnode.length; i++) { - if (pretty && i > 0) rendered += '\n'; - rendered += _renderToString( - vnode[i], - context, - opts, - inner, - isSvgMode, - selectValue - ); + if (pretty && i > 0) rendered = rendered + '\n'; + rendered = + rendered + + _renderToString(vnode[i], context, opts, inner, isSvgMode, selectValue); } return rendered; } @@ -289,7 +284,7 @@ function _renderToString(vnode, context, opts, inner, isSvgMode, selectValue) { opts.attributeHook && opts.attributeHook(name, v, context, opts, isComponent); if (hooked || hooked === '') { - s += hooked; + s = s + hooked; continue; } @@ -303,7 +298,7 @@ function _renderToString(vnode, context, opts, inner, isSvgMode, selectValue) { v = name; // in non-xml mode, allow boolean attributes if (!opts || !opts.xml) { - s += ' ' + name; + s = s + ' ' + name; continue; } } @@ -319,10 +314,10 @@ function _renderToString(vnode, context, opts, inner, isSvgMode, selectValue) { // and the