Skip to content

Commit c2bf701

Browse files
committed
Debounce navigation signal invalidation to prevent redundant updates within a microtask
1 parent bfd0742 commit c2bf701

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

packages/interactivity/src/directives.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,18 @@ export const routerRegions = new Map<
342342
Signal< VNode | null | undefined >
343343
>();
344344

345+
let isNavigationSignalPending = false;
346+
const scheduleNavigationInvalidation = () => {
347+
if ( isNavigationSignalPending ) {
348+
return;
349+
}
350+
isNavigationSignalPending = true;
351+
queueMicrotask( () => {
352+
navigationSignal.value = navigationSignal.peek() + 1;
353+
isNavigationSignalPending = false;
354+
} );
355+
};
356+
345357
export default () => {
346358
// data-wp-context---[unique-id]
347359
directive(
@@ -1027,7 +1039,7 @@ export default () => {
10271039
// been evaluated and the value of the server context has changed.
10281040
useLayoutEffect( () => {
10291041
if ( vdom && typeof vdom.type !== 'string' ) {
1030-
navigationSignal.value = navigationSignal.peek() + 1;
1042+
scheduleNavigationInvalidation();
10311043
}
10321044
}, [ vdom ] );
10331045

0 commit comments

Comments
 (0)