router icon indicating copy to clipboard operation
router copied to clipboard

validateSearch run multiple times even in other routes

Open ruiaraujo012 opened this issue 10 months ago • 0 comments

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

ruiaraujo012 avatar Apr 18 '24 07:04 ruiaraujo012