#zod .catch() in validateSearch create infinity loop

5 messages · Page 1 of 1 (latest)

clever arch
#

Hey
I have this route:

export const paginationSearchSchema = z.object({
  page: z.number().catch(1),
  perPage: z
    .union([
      z.literal(_10_RESULTS_PER_PAGE_),
      z.literal(_15_RESULTS_PER_PAGE_),
      z.literal(_25_RESULTS_PER_PAGE_),
    ])
    .catch(_10_RESULTS_PER_PAGE_),
});

export const Route = createFileRoute('/_authorized/app/users')({
  validateSearch: paginationSearchSchema,
  component: Users,
  beforeLoad: ({ search, context }) => {
    context.queryClient.ensureQueryData(getUsersQueryOptions(search));
  },
});

for some reason adding .catch() in schema make infinity loop and I do not know exactly why this happen.

after some debbuging in found that deleting beforeLoad function in __root.tsx file make this inifnity loop disappear

here is my __root.tsx

export const Route = createRootRouteWithContext<{ queryClient: QueryClient }>()(
  {
    beforeLoad: !getAuth().token
      ? undefined
      : async ({ context: { queryClient } }) => {
          const { token, user } = getAuth();

          if (!user && token) {
            const { data: user } =
              await queryClient.ensureQueryData(getUserData);
            useStore.getState().auth.setUser(user);
          }
        },
    component: GlobalLayout,
  },
);

Anyone know why this happen? I would be very gratefull 🙌
Thanks for reading

fossil quail
clever arch
#

adding this code fix error

  defaultPendingMinMs: 0,```
clever arch
#

or updating to 1.50.0 also helps