Skip to content

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

@mkarajohn

Description

@mkarajohn

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    typesChanges to the typescript types

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions