Skip to content

Commit 5c6877d

Browse files
Unmount option hook call performance (#270)
* Tiny performance improvement for unmount option hook * Create soft-badgers-clap.md --------- Co-authored-by: Jovi De Croock <[email protected]>
1 parent 8cf7cef commit 5c6877d

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

.changeset/soft-badgers-clap.md

Lines 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+
improve unmount option hook call performance

src/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const isArray = Array.isArray;
2121
const assign = Object.assign;
2222

2323
// Global state for the current render pass
24-
let beforeDiff, afterDiff, renderHook;
24+
let beforeDiff, afterDiff, renderHook, ummountHook;
2525

2626
/**
2727
* Render Preact JSX + Components to an HTML string.
@@ -42,6 +42,7 @@ export default function renderToString(vnode, context) {
4242
beforeDiff = options[DIFF];
4343
afterDiff = options[DIFFED];
4444
renderHook = options[RENDER];
45+
ummountHook = options.unmount;
4546

4647
const parent = h(Fragment, null);
4748
parent[CHILDREN] = [vnode];
@@ -236,7 +237,7 @@ function _renderToString(vnode, context, isSvgMode, selectValue, parent) {
236237
if (afterDiff) afterDiff(vnode);
237238
vnode[PARENT] = undefined;
238239

239-
if (options.unmount) options.unmount(vnode);
240+
if (ummountHook) ummountHook(vnode);
240241

241242
return str;
242243
}
@@ -354,7 +355,7 @@ function _renderToString(vnode, context, isSvgMode, selectValue, parent) {
354355

355356
if (afterDiff) afterDiff(vnode);
356357
vnode[PARENT] = undefined;
357-
if (options.unmount) options.unmount(vnode);
358+
if (ummountHook) ummountHook(vnode);
358359

359360
// Emit self-closing tag for empty void elements:
360361
if (!html && SELF_CLOSING.has(type)) {

0 commit comments

Comments
 (0)