Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/soft-badgers-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"preact-render-to-string": patch
---

improve unmount option hook call performance
7 changes: 4 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const isArray = Array.isArray;
const assign = Object.assign;

// Global state for the current render pass
let beforeDiff, afterDiff, renderHook;
let beforeDiff, afterDiff, renderHook, ummountHook;

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

const parent = h(Fragment, null);
parent[CHILDREN] = [vnode];
Expand Down Expand Up @@ -229,7 +230,7 @@ function _renderToString(vnode, context, isSvgMode, selectValue, parent) {
if (afterDiff) afterDiff(vnode);
vnode[PARENT] = undefined;

if (options.unmount) options.unmount(vnode);
if (ummountHook) ummountHook(vnode);

return str;
}
Expand Down Expand Up @@ -346,7 +347,7 @@ function _renderToString(vnode, context, isSvgMode, selectValue, parent) {

if (afterDiff) afterDiff(vnode);
vnode[PARENT] = undefined;
if (options.unmount) options.unmount(vnode);
if (ummountHook) ummountHook(vnode);

// Emit self-closing tag for empty void elements:
if (!html) {
Expand Down