Skip to content

TanStack Router integration navigation spans does not work with throw redirect in loaders #21966

Description

@longzheng

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/react

SDK Version

10.63.0

Framework Version

React 19.2.4, TanStack Router 1.168.7

Link to Sentry event

No response

Reproduction Example/SDK Setup

import * as Sentry from "@sentry/react";
import { createRouter } from "@tanstack/react-router";
const router = createRouter({
  // Your router options...
});
Sentry.init({
  dsn: ...,
  integrations: [Sentry.tanstackRouterBrowserTracingIntegration(router)],
  tracesSampleRate: 1.0,
});

Steps to Reproduce

  1. Create a TanStack route that redirects in the beforeLoad or loader with a throw redirect
export const Route = createFileRoute(`/`)({
    beforeLoad: () => {
        throw Route.redirect({ to: `/test`, replace: true });
    },
});
  1. Start application, visit URL
  2. Check Sentry traces
  3. No navigation span for /test route load

Expected Result

Upon redirect, there should be a navigation span for /test route load

Actual Result

Upon redirect, there is no navigation span for /test. There is only the initial pageload span for /.

Additional Context

This is caused by the TanStack Router bug not emitting onBeforeNavigate if there was a previous redirect thrown in a loader. TanStack/router#3920

Priority

No response

Metadata

Metadata

Assignees

No one assigned

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Waiting for: Product Owner

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions