forge
Explore
Log in

Don't you dare go Hollow

🐛 keep param-route match stores subscribed so useParams never serves stale ids - work around @tanstack/solid-router (<=1.170.18) per-route match store memo losing all observers when the route unmounts and then serving the previous visit's params forever - permanently subscribe every param route's match store from a detached root in router.tsx - fixes exam/event/course/exam-room/live-monitor detail pages showing the previously viewed record after list round-trips

Browse files at this commit

4aecb407a5ab7196e08e1fe1c016d34476c23221Ahmet Kaan GümüşParent: 7122c92
  • fix
    • 🐛 keep param-route match stores subscribed so useParams never serves stale ids - work around @tanstack/solid-router (<=1.170.18) per-route match store memo losing all observers when the route unmounts and then serving the previous visit's params forever - permanently subscribe every param route's match store from a detached root in router.tsx - fixes exam/event/course/exam-room/live-monitor detail pages showing the previously viewed record after list round-trips
Show full message
fix: 🐛 keep param-route match stores subscribed so useParams never serves stale ids - work around @tanstack/solid-router (<=1.170.18) per-route match store memo losing all observers when the route unmounts and then serving the previous visit's params forever - permanently subscribe every param route's match store from a detached root in router.tsx - fixes exam/event/course/exam-room/live-monitor detail pages showing the previously viewed record after list round-trips
src/routes/router.tsxmodified+18 -1
@@ -9,7 +9,7 @@ import {
9 import { getMe } from "@/api/getMe";9 import { getMe } from "@/api/getMe";
10 import { hasMinRole, roleInRange } from "@/lib/roles";10 import { hasMinRole, roleInRange } from "@/lib/roles";
11 import { ApiError } from "@/api/client";11 import { ApiError } from "@/api/client";
12-import { Suspense, lazy, type Component } from "solid-js";12+import { Suspense, createRenderEffect, createRoot, lazy, type Component } from "solid-js";
13 import { AppShell } from "@/components/layout/app-shell";13 import { AppShell } from "@/components/layout/app-shell";
14 import { PageSpinner } from "@/components/ui/page-spinner";14 import { PageSpinner } from "@/components/ui/page-spinner";
15 15
@@ -361,6 +361,23 @@ export const router = createRouter({
361 scrollRestoration: true,361 scrollRestoration: true,
362 });362 });
363 363
364+// Workaround for a @tanstack/solid-router bug (present through v1.170.18):
365+// `useParams({ from })` reads a per-route match store that is a Solid memo
366+// living outside the component tree. When no component on that route is
367+// mounted (e.g. on the list page between two detail visits), the memo has no
368+// observers, misses the next navigation's update, and then serves the
369+// previous visit's params forever — detail pages showed the previously
370+// viewed record. A permanent subscription per param route keeps those memos
371+// observed so they always recompute. Remove once fixed upstream.
372+createRoot(() => {
373+ const paramRouteIds = Object.keys(router.routesById).filter((routeId) => routeId.includes("$"));
374+ for (const routeId of paramRouteIds) {
375+ createRenderEffect(() => {
376+ (router.stores.getRouteMatchStore as (id: string) => { get: () => unknown })(routeId).get();
377+ });
378+ }
379+});
380+
364 declare module "@tanstack/solid-router" {381 declare module "@tanstack/solid-router" {
365 interface Register {382 interface Register {
366 router: typeof router;383 router: typeof router;