Skip to content

Commit 965d0ea

Browse files
committed
Make memory router consistent
1 parent e1170a5 commit 965d0ea

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

packages/react/src/reactrouter-compat-utils/instrumentation.tsx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -388,14 +388,23 @@ export function createV6CompatibleWrapCreateMemoryRouter<
388388
(state.historyAction === 'POP' && isPageloadComplete);
389389

390390
if (shouldHandleNavigation) {
391-
handleNavigation({
392-
location,
393-
routes,
394-
navigationType: state.historyAction,
395-
version,
396-
basename,
397-
allRoutes: Array.from(allRoutes),
398-
});
391+
const navigationHandler = (): void => {
392+
handleNavigation({
393+
location,
394+
routes,
395+
navigationType: state.historyAction,
396+
version,
397+
basename,
398+
allRoutes: Array.from(allRoutes),
399+
});
400+
};
401+
402+
// Wait for the next render if loading an unsettled route
403+
if (state.navigation.state !== 'idle') {
404+
requestAnimationFrame(navigationHandler);
405+
} else {
406+
navigationHandler();
407+
}
399408
}
400409
});
401410

0 commit comments

Comments
 (0)