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

validateSearch run multiple times even in other routes #1481

Open
ruiaraujo012 opened this issue Apr 18, 2024 · 0 comments
Open

validateSearch run multiple times even in other routes #1481

ruiaraujo012 opened this issue Apr 18, 2024 · 0 comments

Comments

@ruiaraujo012
Copy link

ruiaraujo012 commented Apr 18, 2024

Describe the bug

I'm having a strange behavior with one route. The validateSearch is running multiple times even in other routes.
In the images I have my route tree, the logs of validateSearch on other route match, and the validateSearch logs in the route that should validate the search.
As part from that, even my validateSearch is setting the default params if not present, they aren't showing in the url, same #1184
My route file:

const IndividualRecordSearchSchema = v.object({
  tab: v.fallback(v.enum_(TAB_KEYS), DEFAULT_TAB_KEY),
  // eslint-disable-next-line sort-keys
  subTab: v.fallback(v.enum_(SUB_TAB_KEYS), DEFAULT_SUB_TAB_KEY),
});

type IndividualRecordSearch = v.Output<typeof IndividualRecordSearchSchema>;

export const Route = createFileRoute('/_area-reservada/area-reservada/minhas-credenciacoes/ficha-individual')({
  component: () => <IndividualRecordPage />,
  loader: ({ context }) => {
    context.breadcrumbs = [
      {
        label: 'home',
        path: '/area-reservada',
      },
      {
        label: 'myAccreditations',
        path: '/area-reservada/minhas-credenciacoes/credenciacoes',
      },
      {
        label: 'individualRecord',
        path: '/area-reservada/minhas-credenciacoes/ficha-individual',
      },
    ];
  },
  validateSearch: (search: Record<string, unknown>): IndividualRecordSearch => {
    const parsed = v.parse(IndividualRecordSearchSchema, search);

    console.log('parsed >> ', parsed);

    return parsed;
  },
});

Your Example Website or App

https://stackblitz.com/edit/tanstack-router-r3gsvr?file=src%2Froutes%2F_layout%2F_layout-2%2Flayout-a.tsx

Steps to Reproduce the Bug or Issue

Navigating between pages in the sandbox, you can see the logs in the console.

Expected behavior

The validateSearch running only once on the route and never on other routes. As well as putting the search params in the url.

Screenshots or Videos

image
image
image

Platform

  • OS: macOS
  • Browser: Arc
  • Version: 1.28.4

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