T
TanStack4w ago
compatible-crimson

Behaviour of retainSearchParams & stripSearchParams not what expected.

When using both retainSearchParams and stripSearchParams together, the default values are no longer stripped, and then its is not possible to navigate back to the default values after navigating away. Is this the expected behaviour or a bug? For example the params in the url look like this by default gallery?tag=all&sort=popularity&page=1 and when navigating to a different search param, I cannot navigate back to the default
const defaultSearchValues = {
tag: 'all' as const,
sort: 'popularity' as const,
page: 1,
};

const gallerySearchSchema = z.object({
id: z.number().optional(),
searchTerm: z.string().optional(),
tag: z
.enum(['all', 'pro', 'competitive', 'funny', 'streamer', 'favorites'])
.default(defaultSearchValues.tag),
sort: z.enum(['popularity', 'newest']).default(defaultSearchValues.sort),
page: z.number().default(defaultSearchValues.page),
});

export const Route = createFileRoute('/_header/valorant/crosshairs/gallery')({
component: RouteComponent,
validateSearch: zodValidator(gallerySearchSchema),
search: {
middlewares: [
retainSearchParams(['id', 'searchTerm', 'tag', 'sort', 'page']),
stripSearchParams(defaultSearchValues),
],
},
const defaultSearchValues = {
tag: 'all' as const,
sort: 'popularity' as const,
page: 1,
};

const gallerySearchSchema = z.object({
id: z.number().optional(),
searchTerm: z.string().optional(),
tag: z
.enum(['all', 'pro', 'competitive', 'funny', 'streamer', 'favorites'])
.default(defaultSearchValues.tag),
sort: z.enum(['popularity', 'newest']).default(defaultSearchValues.sort),
page: z.number().default(defaultSearchValues.page),
});

export const Route = createFileRoute('/_header/valorant/crosshairs/gallery')({
component: RouteComponent,
validateSearch: zodValidator(gallerySearchSchema),
search: {
middlewares: [
retainSearchParams(['id', 'searchTerm', 'tag', 'sort', 'page']),
stripSearchParams(defaultSearchValues),
],
},
2 Replies
eastern-cyan
eastern-cyan3w ago
GitHub
Router searchParameter gets reset to default value (of zod schema) ...
Which project does this relate to? Router Describe the bug Using retained searchParams, if we change the retained param x form a to b on some route (lets say route-a) and we navigate to route-b, wh...
eastern-cyan
eastern-cyan3w ago
GitHub
Navigation with retainSearchParams middleware not working · Issue ...
Which project does this relate to? Router Describe the bug Navigating when using a retainSearchParams middleware seems to be broken. The URL for the link shows the search parameter but once we navi...

Did you find this page helpful?