Skip to content

Commit

Permalink
fix: better queue of routing update
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBLT committed Mar 9, 2024
1 parent a2becfb commit 5a53e43
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 10 additions & 1 deletion packages/@hec.js/ui/lib/src/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export const query = signal({});
export const route = signal(location.pathname);

const _pushState = window.history.pushState,
_replaceState = window.history.replaceState;
_replaceState = window.history.replaceState,
state = { updateQueued: false };

/**
* @typedef {{
Expand Down Expand Up @@ -60,6 +61,12 @@ export function addRoute(route) {

targetRoutes.push(route);
targetRoutes.sort(routeCompare);

if (state.updateQueued) {
state.updateQueued = true;

queueMicrotask(updateRouting);
}
}

export function navigate(path = '') {
Expand Down Expand Up @@ -106,6 +113,8 @@ export const updateRouting = () => {
return hasFullMatch;
}

state.updateQueued = false;

return updateGroup(routes);
}

Expand Down
2 changes: 0 additions & 2 deletions packages/@hec.js/ui/lib/src/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ export function templateByNode(template, props = {}) {

findExpression(template, new WeakSet());

queueMicrotask(updateRouting);

return template;
}

Expand Down

0 comments on commit 5a53e43

Please sign in to comment.