File tree Expand file tree Collapse file tree 1 file changed +12
-7
lines changed
Expand file tree Collapse file tree 1 file changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,9 @@ export const useHistoryStore = create(
1919 registerRoute ( route ) {
2020 set ( ( s ) => {
2121 s . routes . push ( route ) ;
22+ if ( s . routes . length > 50 ) {
23+ s . routes . shift ( ) ;
24+ }
2225 } ) ;
2326 } ,
2427 } ) ) ,
@@ -40,16 +43,18 @@ export function useLastNonPlayerLink() {
4043 const routes = useHistoryStore ( ( s ) => s . routes ) ;
4144 const location = useLocation ( ) ;
4245 const lastNonPlayerLink = useMemo ( ( ) => {
43- const reversedRoutes = [ ...routes ] ;
44- reversedRoutes . reverse ( ) ;
45- const route = reversedRoutes . find (
46- ( v ) =>
46+ for ( let i = routes . length - 1 ; i >= 0 ; i -= 1 ) {
47+ const v = routes [ i ] ;
48+ if (
4749 ! v . path . startsWith ( "/media" ) && // cannot be a player link
4850 location . pathname !== v . path && // cannot be current link
4951 ! v . path . startsWith ( "/s/" ) && // cannot be a quick search link
50- ! v . path . startsWith ( "/onboarding" ) , // cannot be an onboarding link
51- ) ;
52- return route ?. path ?? "/" ;
52+ ! v . path . startsWith ( "/onboarding" ) // cannot be an onboarding link
53+ ) {
54+ return v . path ;
55+ }
56+ }
57+ return "/" ;
5358 } , [ routes , location ] ) ;
5459 return lastNonPlayerLink ;
5560}
You can’t perform that action at this time.
0 commit comments