Skip to content

Commit

Permalink
refactor: minor tidy to new navigation in router
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanl17 committed Feb 13, 2025
1 parent cf79bdd commit 31ae559
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions packages/sanity/src/router/RouterProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,8 @@ export function RouterProvider(props: RouterProviderProps): React.JSX.Element {
throw new Error('One or more parameters are not sticky')
}

// Use helper to merge sticky params
const searchParams = mergeStickyParams(state._searchParams || [], params)

// Trigger navigation with updated params
onNavigate({
path: resolvePathFromState({
...state,
Expand All @@ -146,14 +144,11 @@ export function RouterProvider(props: RouterProviderProps): React.JSX.Element {
const currentParams = Array.isArray(state._searchParams) ? state._searchParams : []
const nextParams = Array.isArray(nextState._searchParams) ? nextState._searchParams : []

// Merge sticky params using the helper function
const mergedParams = mergeStickyParams(
nextParams, // Ensure it's always an array
nextParams,
options.stickyParams ??
Object.fromEntries(currentParams.filter(([key]) => STICKY_PARAMS.includes(key))), // Preserve sticky params unless overridden
Object.fromEntries(currentParams.filter(([key]) => STICKY_PARAMS.includes(key))),
)

// Construct new state
const mergedState = {...nextState, _searchParams: mergedParams}

onNavigate({path: resolvePathFromState(mergedState), replace: options.replace})
Expand Down

0 comments on commit 31ae559

Please sign in to comment.