Skip to content

fix(router-core): handle matches whose routes are removed from routeTree #7797

Open

Description

@LadyBluenotes

Problem

Applications can replace routeTree while existing, pending, or cached matches still reference routes removed from the new tree.

Route lookups through looseRoutesById[match.routeId] then return undefined. This can crash cache cleanup, Devtools age rendering, and lifecycle callback dispatch.

Scope

  • Evict cached matches whose route no longer exists during clearExpiredCache.
  • Make Devtools AgeTicker render nothing for an orphaned match.
  • Skip lifecycle callback dispatch for matches whose route has been removed.
  • Preserve existing behavior for current routes and for routes without loaders.
  • Add router-core regression coverage that loads a route, replaces the route tree without it, and completes a navigation or cache-cleanup cycle without throwing.
  • Add focused Devtools coverage for an orphaned match in AgeTicker.

Related Work

Activity

  1. constantly-dev commented on Aug 31, 2026

    @constantly-dev

    Hi @LadyBluenotes — happy to take this on if it's still open.

    One thing I want to check before starting:
    after the loader rewrite (#7805), the routesById lookup lives in getRoute() (load-client.ts), which currently returns AnyRoute (non-optional) and ends in a ! assertion.

    Fixing this at the root means widening the return type to AnyRoute | undefined and adding early returns at every call site — plus the same guard in runRouteLifecycle() and AgeTicker.tsx. Is that the scope you had in mind, or would you rather keep the return type as-is and guard only at the specific crash sites?

    Can you assign this to me?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions