authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-02-26 18:58:59-08:00
committergravatar for jmarminge@gmail.comJulius Marminge <jmarminge@gmail.com> 2026-02-26 21:05:53-08:00
log69a2eac2ff1ba0af1afd0334514789340051cab2
tree4cb8e880013e4392ae6fd4492c4a7a2f57d43772
parent5fd632c357914553f2baf746df0454527db89b09

Use pathname ref in EventRouter bootstrap navigation

- Track latest `pathname` in a ref for bootstrap event handling - Prevent effect resubscriptions by removing `pathname` from deps - Keep auto-navigation gated to root route using current path

1 files changed, 4 insertions(+), 2 deletions(-)

apps/web/src/routes/__root.tsx+4-2
......@@ -127,8 +127,10 @@ function EventRouter() {
127127 const queryClient = useQueryClient();
128128 const navigate = useNavigate();
129129 const pathname = useRouterState({ select: (state) => state.location.pathname });
130 const pathnameRef = useRef(pathname);
130131 const lastConfigIssuesSignatureRef = useRef<string | null>(null);
131132 const handledBootstrapThreadIdRef = useRef<string | null>(null);
133 pathnameRef.current = pathname;
132134
133135 useEffect(() => {
134136 const api = readNativeApi();
......@@ -201,7 +203,7 @@ function EventRouter() {
201203 projectId: payload.bootstrapProjectId,
202204 expanded: true,
203205 });
204 if (pathname !== "/") {
206 if (pathnameRef.current !== "/") {
205207 return;
206208 }
207209 if (handledBootstrapThreadIdRef.current === payload.bootstrapThreadId) {
......@@ -264,7 +266,7 @@ function EventRouter() {
264266 unsubWelcome();
265267 unsubServerConfigUpdated();
266268 };
267 }, [dispatch, navigate, pathname, queryClient]);
269 }, [dispatch, navigate, queryClient]);
268270
269271 return null;
270272}