From 9aa6e4088abfc5215949f09af3806c6b8970463d Mon Sep 17 00:00:00 2001 From: Pas <74743263+Pasithea0@users.noreply.github.com> Date: Sun, 22 Feb 2026 22:12:31 -0700 Subject: [PATCH] make router history a bit safer --- src/stores/history/index.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/stores/history/index.ts b/src/stores/history/index.ts index c1f507ee..7c5cbf33 100644 --- a/src/stores/history/index.ts +++ b/src/stores/history/index.ts @@ -19,6 +19,9 @@ export const useHistoryStore = create( registerRoute(route) { set((s) => { s.routes.push(route); + if (s.routes.length > 50) { + s.routes.shift(); + } }); }, })), @@ -40,16 +43,18 @@ export function useLastNonPlayerLink() { const routes = useHistoryStore((s) => s.routes); const location = useLocation(); const lastNonPlayerLink = useMemo(() => { - const reversedRoutes = [...routes]; - reversedRoutes.reverse(); - const route = reversedRoutes.find( - (v) => + for (let i = routes.length - 1; i >= 0; i -= 1) { + const v = routes[i]; + if ( !v.path.startsWith("/media") && // cannot be a player link location.pathname !== v.path && // cannot be current link !v.path.startsWith("/s/") && // cannot be a quick search link - !v.path.startsWith("/onboarding"), // cannot be an onboarding link - ); - return route?.path ?? "/"; + !v.path.startsWith("/onboarding") // cannot be an onboarding link + ) { + return v.path; + } + } + return "/"; }, [routes, location]); return lastNonPlayerLink; }