Skip to content

Commit

Permalink
fix(router): use startTransition (#742)
Browse files Browse the repository at this point in the history
follow up #737
  • Loading branch information
dai-shi authored Jun 5, 2024
1 parent 97f5bc8 commit 5edb781
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions packages/waku/src/router/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Component,
createContext,
createElement,
startTransition,
useCallback,
useContext,
useEffect,
Expand Down Expand Up @@ -333,7 +334,9 @@ const InnerRouter = ({ routerData }: { routerData: RouterData }) => {
const changeRoute: ChangeRoute = useCallback(
(route, options) => {
const { checkCache, skipRefetch } = options || {};
setRoute(route);
startTransition(() => {
setRoute(route);
});
const componentIds = getComponentIds(route.path);
if (
checkCache &&
Expand Down Expand Up @@ -364,14 +367,16 @@ const InnerRouter = ({ routerData }: { routerData: RouterData }) => {
]),
);
}
setCached((prev) => ({
...prev,
...Object.fromEntries(
componentIds.flatMap((id) =>
skip.includes(id) ? [] : [[id, route]],
startTransition(() => {
setCached((prev) => ({
...prev,
...Object.fromEntries(
componentIds.flatMap((id) =>
skip.includes(id) ? [] : [[id, route]],
),
),
),
}));
}));
});
},
[refetch, routerData],
);
Expand Down

0 comments on commit 5edb781

Please sign in to comment.