Skip to content

Commit

Permalink
perf: remove unnecessary closure
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister committed Apr 8, 2024
1 parent 720c9b7 commit ab55e38
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,9 @@ function _renderToString(
rendered != null && rendered.type === Fragment && rendered.key == null;
rendered = isTopLevelFragment ? rendered.props.children : rendered;

const renderChildren = () =>
_renderToString(
try {
// Recurse into children before invoking the after-diff hook
const str = _renderToString(
rendered,
context,
isSvgMode,
Expand All @@ -448,10 +449,6 @@ function _renderToString(
asyncMode
);

try {
// Recurse into children before invoking the after-diff hook
const str = renderChildren();

if (afterDiff) afterDiff(vnode);
vnode[PARENT] = null;

Expand All @@ -465,12 +462,27 @@ function _renderToString(

const renderNestedChildren = () => {
try {
return renderChildren();
return _renderToString(
rendered,
context,
isSvgMode,
selectValue,
vnode,
asyncMode
);
} catch (e) {
if (!e || typeof e.then !== 'function') throw e;

return e.then(
() => renderChildren(),
() =>
_renderToString(
rendered,
context,
isSvgMode,
selectValue,
vnode,
asyncMode
),
() => renderNestedChildren()
);
}
Expand Down

0 comments on commit ab55e38

Please sign in to comment.