Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions packages/router-core/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1699,19 +1699,6 @@ export class RouterCore<
// _includeValidateSearch: true,
// })

// Accumulate search validation through route chain
const accumulatedSearch = { ...location.search }
for (const route of matchedRoutes) {
try {
Object.assign(
accumulatedSearch,
validateSearch(route.options.validateSearch, accumulatedSearch),
)
} catch {
// Ignore errors, we're not actually routing
}
}

// Determine params: reuse from state if possible, otherwise parse
const lastStateMatchId = last(this.stores.matchesId.state)
const lastStateMatch =
Expand Down Expand Up @@ -1749,7 +1736,7 @@ export class RouterCore<
return {
matchedRoutes,
fullPath: lastRoute.fullPath,
search: accumulatedSearch,
search: location.search,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep validated search when reusing current search

This drops the route-validated/defaulted search state whenever a caller preserves or updates the current search (search: true or search: prev => ...). buildLocation callers like the framework Link components (packages/react-router/src/link.tsx:418-419) and redirects (packages/router-core/src/router.ts:2711-2714) do not pass _includeValidateSearch, so they now see the raw parsed query instead of the validated one. In the redirect scenario covered by packages/react-router/tests/link.test.tsx:3948-4019, the callback should receive { postPage: 0 } from the current route's validateSearch, but after this change it receives {}, so links/redirects to routes that do not reintroduce the same validator lose existing defaulted params and generate the wrong URL/search state.

Useful? React with 👍 / 👎.

params,
}
}
Expand Down
Loading