Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ee7bc5a

Browse filesBrowse files
Merge pull request #348 from preactjs/remove-closure
perf: remove unnecessary closure
2 parents e9a53aa + 303b8c0 commit ee7bc5a
Copy full SHA for ee7bc5a

File tree

Expand file treeCollapse file tree

2 files changed

+25
-8
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+25
-8
lines changed

‎.changeset/perfect-hounds-joke.md

Copy file name to clipboard
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'preact-render-to-string': patch
3+
---
4+
5+
Perf: Remove unnecessary closure when rendering child nodes

‎src/index.js

Copy file name to clipboardExpand all lines: src/index.js
+20-8Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,9 @@ function _renderToString(
441441
rendered.props.tpl == null;
442442
rendered = isTopLevelFragment ? rendered.props.children : rendered;
443443

444-
const renderChildren = () =>
445-
_renderToString(
444+
try {
445+
// Recurse into children before invoking the after-diff hook
446+
const str = _renderToString(
446447
rendered,
447448
context,
448449
isSvgMode,
@@ -451,10 +452,6 @@ function _renderToString(
451452
asyncMode
452453
);
453454

454-
try {
455-
// Recurse into children before invoking the after-diff hook
456-
const str = renderChildren();
457-
458455
if (afterDiff) afterDiff(vnode);
459456
vnode[PARENT] = null;
460457

@@ -468,12 +465,27 @@ function _renderToString(
468465

469466
const renderNestedChildren = () => {
470467
try {
471-
return renderChildren();
468+
return _renderToString(
469+
rendered,
470+
context,
471+
isSvgMode,
472+
selectValue,
473+
vnode,
474+
asyncMode
475+
);
472476
} catch (e) {
473477
if (!e || typeof e.then !== 'function') throw e;
474478

475479
return e.then(
476-
() => renderChildren(),
480+
() =>
481+
_renderToString(
482+
rendered,
483+
context,
484+
isSvgMode,
485+
selectValue,
486+
vnode,
487+
asyncMode
488+
),
477489
() => renderNestedChildren()
478490
);
479491
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.