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

Search params get stripped if validateSearch throws and beforeLoad redirects #3120

Open
Sheraff opened this issue Jan 7, 2025 · 0 comments

Comments

@Sheraff
Copy link

Sheraff commented Jan 7, 2025

Which project does this relate to?

Router

Describe the bug

If a route has both a validateSearch and a beforeLoad that redirects:

export const Route = createFileRoute('/about')({
  validateSearch: zod.object({
    a: zod.number(),
  }),
  beforeLoad: async ({ search }) => {
    throw redirect({ to: '/third', search });
  },
});

When landing on such page with an invalid search, the search object forwarded through the redirection is an empty object.

Your Example Website or App

https://stackblitz.com/edit/tanstack-router-yhzqerey?file=src%2Froutes%2Fabout.tsx

Steps to Reproduce the Bug or Issue

  1. from the / homepage on the stackblitz repro above
  2. click on the "to about page with search" link

Expected behavior

I would have expected either:

  • to remain on the "/about" page, in an error state (errorComponent)
  • or to be redirected to the "/third" page, with the search untouched

But instead, we're redirected correctly, but the search becomes an empty object. There is no indication of an error:

  • no errorComponent gets mounted
  • no onError callback gets called

Screenshots or Videos

No response

Platform

  • OS: macOS
  • Browser: Chrome
  • Version: 1.95.1

Additional context

No response

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

1 participant