Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/router-core/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2259,9 +2259,9 @@ export class RouterCore<
clearExpiredCache = () => {
// This is where all of the garbage collection magic happens
const filter = (d: MakeRouteMatch<TRouteTree>) => {
const route = this.looseRoutesById[d.routeId]!
const route = this.looseRoutesById[d.routeId]

Copy link
Contributor

Choose a reason for hiding this comment

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

should we not just return here if route is undefined?

if (!route.options.loader) {
if (!route?.options.loader) {
return true
}

Expand Down
4 changes: 2 additions & 2 deletions packages/router-devtools-core/src/AgeTicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ export function AgeTicker({
return null
}

const route = router().looseRoutesById[match.routeId]!
const route = router().looseRoutesById[match.routeId]

if (!route.options.loader) {
if (!route?.options.loader) {
return null
Comment on lines +38 to 41
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Type-safety: add explicit null check to narrow route.

if (!route?.options.loader) does not narrow route in TS strict mode, and route.options.* below will error. Guard route first.

Apply this diff:

-  const route = router().looseRoutesById[match.routeId]
-
-  if (!route?.options.loader) {
+  const route = router().looseRoutesById[match.routeId]
+  if (!route || !route.options.loader) {
     return null
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const route = router().looseRoutesById[match.routeId]
if (!route.options.loader) {
if (!route?.options.loader) {
return null
const route = router().looseRoutesById[match.routeId]
if (!route || !route.options.loader) {
return null
🤖 Prompt for AI Agents
In packages/router-devtools-core/src/AgeTicker.tsx around lines 38 to 41, the
current check uses optional chaining (if (!route?.options.loader)) which does
not narrow `route` under TS strict mode and will cause later accesses to
`route.options` to error; change the guard to first check for `route` explicitly
(for example: if (!route || !route.options.loader) return null) so TypeScript
narrows `route` and subsequent `route.options.*` access is safe.

}

Expand Down