Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throwing redirect in beforeLoad still renders component #2820

Closed
isaachinman opened this issue Nov 21, 2024 · 2 comments
Closed

Throwing redirect in beforeLoad still renders component #2820

isaachinman opened this issue Nov 21, 2024 · 2 comments

Comments

@isaachinman
Copy link

isaachinman commented Nov 21, 2024

Which project does this relate to?

Router

Describe the bug

This could be similar to #2819, but the behaviour I am observing is slightly different:

export const Route = createFileRoute('/some-path')({
  beforeLoad: async () => {
    if (2 + 2 === 4) {
      console.log('throwing')
      throw redirect({
        to: '/some-other-path',
      })
    }
  },
  component: () => {
    console.log('component is running')

    return <Outlet />
  },
})

If I hit this URL, I see this in the console:

throwing
component is running

Apologies if I've misunderstood the purpose of beforeLoad, but isn't this as straightforward a bug as there could be?

EDIT: This is related to #2818. If I set TanStackRouterVite.autoCodeSplitting to false, the bug no longer occurs.

Your Example Website or App

http://example.com

Steps to Reproduce the Bug or Issue

export const Route = createFileRoute('/some-path')({
  beforeLoad: async () => {
    if (2 + 2 === 4) {
      console.log('throwing')
      throw redirect({
        to: '/some-other-path',
      })
    }
  },
  component: () => {
    console.log('component is running')

    return <Outlet />
  },
})

Expected behavior

Component should not be run.

Screenshots or Videos

No response

Platform

  • OS: [e.g. macOS, Windows, Linux]
  • Browser: [e.g. Chrome, Safari, Firefox]
  • Version: [e.g. 91.1]

Additional context

No response

@schiller-manuel
Copy link
Contributor

please provide a minimal complete example by forking an existing example on stackblitz

@isaachinman
Copy link
Author

I've provided the minimal repro via a code snippet, and further follow-up investigation. I have isolated the problem for you.

I will gladly close this issue. You can deal with the next user to report it, and they can jump through your hoops.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants