Skip to content
Source
Sign inSign up
TanStack/router

beforeLoad return type circular reference error regression somewhere between versions 1.130.12 and 1.134.13 #5786

Send to my agent
Openmkarajohn(GitHub profile, opens in a new tab) opened this issue 4 comments

Which project does this relate to?

Router

Describe the bug

This piece of code

export const Route = createFileRoute('/_authenticated')({
  beforeLoad: ({ context }) => {
    return {
      crumbs: [
        ...context.crumbs,
        {
          text: 'Some Text',
          // ❌ This line breaks type inference
          to: Route.fullPath,
        },
      ],
    };
  },
  component: RouteComponent,
});

works ok in 1.130.12 without any TS errors

Image

Your Example Website or App

https://stackblitz.com/edit/github-vblwkxuv?file=src%2Froutes%2F_authenticated%2Froute.tsx

Steps to Reproduce the Bug or Issue

Use the code example above in versions beyond 1.130.12. The fact that we are using the Route reference inside beforeLoad causes the type error. (there is no actual runtime error, since this is valid object reference inside the function body, similar to

function createObj(x: string) {
  return function <T>(x: T) {
    return x
  }
}

const test = createObj('')({
  a: 1,
  func: () => {
    return test.a
  },
})

)

Expected behavior

For the above code to work with no type errors

Screenshots or Videos

Image Image Image

Platform

  • Router: 1.134.13
  • OS: Linux
  • Browser: Chrome
  • Browser Version: 142.0.7444.134
  • Bundler: vite
  • Bundler Version: 7.2.2

Additional context

No response

  1. @schiller-manuel any plans for this regression? Thanks

  2. eventually yes. not a high priority right now

  3. I just want to give some extra feedback on this, in case it affects the priority:

    It's not just the errors about self reference; it affects stuff such as search params to links or navigations as well. For example, see how many linter errors are produced in the RouteComponent because of the initial self-reference error. Practically every search param shows up as "any" (hence the linter errors)

    Image

    linter errors when we reference the Route in the beforeload

    Image

    vs linter errors without that initial error

  4. Opened this: https://github.com/TanStack/router/pull/6936

    It's AI generated, with steering on my part. Seems to resolve the issue locally, so please let me know if it's up to par implementation wise too

    disregard for now, sorry

Sign in to join this conversation.