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() {...@@ -127,8 +127,10 @@ function EventRouter() {
127 const queryClient = useQueryClient();127 const queryClient = useQueryClient();
128 const navigate = useNavigate();128 const navigate = useNavigate();
129 const pathname = useRouterState({ select: (state) => state.location.pathname });129 const pathname = useRouterState({ select: (state) => state.location.pathname });
130 const pathnameRef = useRef(pathname);
130 const lastConfigIssuesSignatureRef = useRef<string | null>(null);131 const lastConfigIssuesSignatureRef = useRef<string | null>(null);
131 const handledBootstrapThreadIdRef = useRef<string | null>(null);132 const handledBootstrapThreadIdRef = useRef<string | null>(null);
133 pathnameRef.current = pathname;
132134
133 useEffect(() => {135 useEffect(() => {
134 const api = readNativeApi();136 const api = readNativeApi();
...@@ -201,7 +203,7 @@ function EventRouter() {...@@ -201,7 +203,7 @@ function EventRouter() {
201 projectId: payload.bootstrapProjectId,203 projectId: payload.bootstrapProjectId,
202 expanded: true,204 expanded: true,
203 });205 });
204 if (pathname !== "/") {206 if (pathnameRef.current !== "/") {
205 return;207 return;
206 }208 }
207 if (handledBootstrapThreadIdRef.current === payload.bootstrapThreadId) {209 if (handledBootstrapThreadIdRef.current === payload.bootstrapThreadId) {
...@@ -264,7 +266,7 @@ function EventRouter() {...@@ -264,7 +266,7 @@ function EventRouter() {
264 unsubWelcome();266 unsubWelcome();
265 unsubServerConfigUpdated();267 unsubServerConfigUpdated();
266 };268 };
267 }, [dispatch, navigate, pathname, queryClient]);269 }, [dispatch, navigate, queryClient]);
268270
269 return null;271 return null;
270}272}