Skip to content

refactor(router-core): minor cleanup of loadMatches #4799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Sheraff
Copy link
Contributor

@Sheraff Sheraff commented Jul 27, 2025

This PR is a minor cleanup of router.ts

  • use .some() instead of .find() when we only need a boolean result
  • the result of updateMatch is never used, so don't return anything
  • getMatch doesn't need to create an array of all matches
  • loadMatches
    • doesn't need to create a promise explicitly, itself is an async function already
    • can skip some code if there is no route.options.beforeLoad
    • can skip some code if there is no route.options.loader

And some minor "don't create an object if you don't need to".


A good goal would be to try and make loadMatches much lighter by updating the store less (fewer calls to updateMatch) as this can trigger a lot of synchronous code execution every time. But this PR only does minor cleanup because the big refactor is scary.

Copy link

nx-cloud bot commented Jul 27, 2025

View your CI Pipeline Execution ↗ for commit 2bee3e9

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ❌ Failed 17m 38s View ↗

☁️ Nx Cloud last updated this comment at 2025-07-28 09:53:47 UTC

Copy link

pkg-pr-new bot commented Jul 27, 2025

More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@4799

@tanstack/directive-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@4799

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@4799

@tanstack/history

npm i https://pkg.pr.new/TanStack/router/@tanstack/history@4799

@tanstack/react-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@4799

@tanstack/react-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@4799

@tanstack/react-router-with-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-with-query@4799

@tanstack/react-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@4799

@tanstack/react-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@4799

@tanstack/react-start-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-plugin@4799

@tanstack/react-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@4799

@tanstack/router-cli

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@4799

@tanstack/router-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@4799

@tanstack/router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@4799

@tanstack/router-devtools-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@4799

@tanstack/router-generator

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@4799

@tanstack/router-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@4799

@tanstack/router-utils

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@4799

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@4799

@tanstack/server-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@4799

@tanstack/solid-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@4799

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@4799

@tanstack/solid-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@4799

@tanstack/solid-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@4799

@tanstack/solid-start-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-plugin@4799

@tanstack/solid-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@4799

@tanstack/start-client-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@4799

@tanstack/start-plugin-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@4799

@tanstack/start-server-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@4799

@tanstack/start-server-functions-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-functions-client@4799

@tanstack/start-server-functions-fetcher

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-functions-fetcher@4799

@tanstack/start-server-functions-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-functions-server@4799

@tanstack/start-storage-context

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@4799

@tanstack/valibot-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@4799

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@4799

@tanstack/zod-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@4799

commit: 2bee3e9

@Sheraff Sheraff changed the title refactor(router-core): minor cleanup of router refactor(router-core): minor cleanup of loadMatches Jul 27, 2025
@Sheraff Sheraff requested a review from schiller-manuel July 27, 2025 21:29
...(this.state.pendingMatches ?? []),
...this.state.matches,
].find((d) => d.id === matchId)
const find = (d: { id: string }) => d.id === matchId
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const find = (d: { id: string }) => d.id === matchId
const findFn = (d: { id: string }) => d.id === matchId

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really know what I broke in this PR that I thought was basic, so I applied your proposed change in a separate PR that just touches that method #4824

@@ -2858,7 +2813,7 @@ export class RouterCore<
: (route.options.gcTime ?? this.options.defaultGcTime)) ??
5 * 60 * 1000

return !(d.status !== 'error' && Date.now() - d.updatedAt < gcTime)
return d.status === 'error' && Date.now() - d.updatedAt >= gcTime
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we break up one-liner into a couple of booleans? with variables like isError and isElapsed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants