Skip to content

Commit

Permalink
Merge pull request #3921 from preactjs/hoist-render-queue-sort
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister authored Feb 28, 2023
2 parents bf39376 + b060516 commit 950b239
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,16 @@ export function enqueueRender(c) {
}
}

/**
* @param {import('./internal').Component} a
* @param {import('./internal').Component} b
*/
const depthSort = (a, b) => a._vnode._depth - b._vnode._depth;

/** Flush the render queue by rerendering all queued components */
function process() {
let c;
rerenderQueue.sort((a, b) => a._vnode._depth - b._vnode._depth);
rerenderQueue.sort(depthSort);
// Don't update `renderCount` yet. Keep its value non-zero to prevent unnecessary
// process() calls from getting scheduled while `queue` is still being consumed.
while ((c = rerenderQueue.shift())) {
Expand All @@ -219,7 +225,7 @@ function process() {
// When i.e. rerendering a provider additional new items can be injected, we want to
// keep the order from top to bottom with those new items so we can handle them in a
// single pass
rerenderQueue.sort((a, b) => a._vnode._depth - b._vnode._depth);
rerenderQueue.sort(depthSort);
}
}
}
Expand Down

0 comments on commit 950b239

Please sign in to comment.