From 4aecb407a5ab7196e08e1fe1c016d34476c23221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 16 Jul 2026 15:52:58 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20keep=20param-route=20matc?= =?UTF-8?q?h=20stores=20subscribed=20so=20useParams=20never=20serves=20sta?= =?UTF-8?q?le=20ids=20-=20work=20around=20@tanstack/solid-router=20(<=3D1.?= =?UTF-8?q?170.18)=20per-route=20match=20store=20memo=20losing=20all=20obs?= =?UTF-8?q?ervers=20when=20the=20route=20unmounts=20and=20then=20serving?= =?UTF-8?q?=20the=20previous=20visit's=20params=20forever=20-=20permanentl?= =?UTF-8?q?y=20subscribe=20every=20param=20route's=20match=20store=20from?= =?UTF-8?q?=20a=20detached=20root=20in=20router.tsx=20-=20fixes=20exam/eve?= =?UTF-8?q?nt/course/exam-room/live-monitor=20detail=20pages=20showing=20t?= =?UTF-8?q?he=20previously=20viewed=20record=20after=20list=20round-trips?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/routes/router.tsx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/routes/router.tsx b/src/routes/router.tsx index 9775944..f81dbae 100644 --- a/src/routes/router.tsx +++ b/src/routes/router.tsx @@ -9,7 +9,7 @@ import { import { getMe } from "@/api/getMe"; import { hasMinRole, roleInRange } from "@/lib/roles"; import { ApiError } from "@/api/client"; -import { Suspense, lazy, type Component } from "solid-js"; +import { Suspense, createRenderEffect, createRoot, lazy, type Component } from "solid-js"; import { AppShell } from "@/components/layout/app-shell"; import { PageSpinner } from "@/components/ui/page-spinner"; @@ -361,6 +361,23 @@ export const router = createRouter({ scrollRestoration: true, }); +// Workaround for a @tanstack/solid-router bug (present through v1.170.18): +// `useParams({ from })` reads a per-route match store that is a Solid memo +// living outside the component tree. When no component on that route is +// mounted (e.g. on the list page between two detail visits), the memo has no +// observers, misses the next navigation's update, and then serves the +// previous visit's params forever — detail pages showed the previously +// viewed record. A permanent subscription per param route keeps those memos +// observed so they always recompute. Remove once fixed upstream. +createRoot(() => { + const paramRouteIds = Object.keys(router.routesById).filter((routeId) => routeId.includes("$")); + for (const routeId of paramRouteIds) { + createRenderEffect(() => { + (router.stores.getRouteMatchStore as (id: string) => { get: () => unknown })(routeId).get(); + }); + } +}); + declare module "@tanstack/solid-router" { interface Register { router: typeof router;