Skip to content

Commit 4640a52

Browse files
committed
fix(routing): useActiveRouteEvents not re-rendering
Because the context value was a mutable ref it never triggered a context change so the hook only ran when the component rendered for other reasons This causes the context value to be re-created every time the active route changes to ensure components using it will re-render when that happens
1 parent 95be0b9 commit 4640a52

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/tests/asyncRouteRedirects.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ describe("async route redirects", () => {
8989

9090
childRoute.navigate({ params: { bar: "redirect", notFoo: "foo" } });
9191

92-
await delay(140);
92+
await delay(200);
9393
expect(queryByText("redirected")).toBeDefined();
9494
expect(hist.location.pathname).toBe("/notFoo/foo/redirected/child/");
9595
});

src/xstateTree.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,14 +495,16 @@ export function buildRootComponent(
495495
}, []);
496496

497497
const routingProviderValue = useMemo(() => {
498+
// Just to satisfy linter, need this memo to be re-calculated on route changes
499+
activeRoute;
498500
if (!routing) {
499501
return null;
500502
}
501503

502504
return {
503505
activeRouteEvents: activeRouteEventsRef,
504506
};
505-
}, []);
507+
}, [activeRoute]);
506508

507509
if (!interpreter.initialized) {
508510
setTimeout(() => forceRender(!forceRenderValue), 0);

0 commit comments

Comments
 (0)