Skip to content

Commit

Permalink
Unmount option hook call performance (#270)
Browse files Browse the repository at this point in the history
* Tiny performance improvement for unmount option hook

* Create soft-badgers-clap.md

---------

Co-authored-by: Jovi De Croock <decroockjovi@gmail.com>
  • Loading branch information
developit and JoviDeCroock committed Feb 25, 2023
1 parent 8cf7cef commit 5c6877d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
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 @@ -236,7 +237,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 @@ -354,7 +355,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 && SELF_CLOSING.has(type)) {
Expand Down

0 comments on commit 5c6877d

Please sign in to comment.