#search params appear in `_strictSearch` but not in `search`

1 messages · Page 1 of 1 (latest)

frigid rapids
#

Im encountering a problem where my search params show up in the URL as expected, but wont be available using Route.useSearch().
Using the devtools i can see that they appear in the parent routes search, but only appear in the /page route under _strictSearch. Anyone knows how this could happen?

export const Route = createFileRoute(
  "/x/$projectId/_layout/page"
)({
  component: MyComponent,
  validateSearch: zodValidator(
    z.object({
      foo: fallback(z.string().optional(), "foo").default("foo"),
      bar: fallback(z.string().optional(), "bar").default("bar"),
      baz: fallback(z.string().optional(), "baz").default("baz")
    })
  ),
});

function MyComponent() {
  const search = Route.useSearch();
  console.log("search", search);

  return null;
}
livid whale
#

can you please create a complete example by forking one of the router examples on stackblitz ?

frigid rapids
#

i tried creating an example, but im unable to reproduce it. so i guess im just looking for any guesses what could potentially be going wrong.

#

from looking at it _strictSearch includes all search params and search only contains the ones that passed validation?

livid whale
#

should be the other way round. btw strict search is not public API so ideally you should not worry about that usually

frigid rapids
#

hm, then its even weirder to me

frigid rapids
#

i found the culprit, it was caused by a sibling routes (/x/$projectId/_layout/page-b) search middleware. how can that even affect another route? 😕

#

the middleware in question, which is part of /x/$projectId/_layout/page-b(aka sibling route)

search: {
    middlewares: [
      ({ search, next }) => {
        const result = next(search);
        Object.keys(result).forEach(key => {
          if (!Object.keys(searchSchema.shape).includes(key)) {
            delete result[key as keyof typeof searchSchema.shape];
          }
        });

        return result;
      }
    ]
  },
#

why does this seemingly run on /x/$projectId/_layout/page?

livid whale
#

a search middleware runs for links pointing from one route to another

#

you should not manipulate the passed in value directly

#

return a modified copy

#

i guess that's the issue here

frigid rapids
#

dang, yea that fixed it