Skip to content

Commit

Permalink
chore: Remove default getSearchParamsSnapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
franky47 committed Dec 17, 2024
1 parent 2485852 commit c35fb8c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
9 changes: 2 additions & 7 deletions packages/nuqs/src/adapters/lib/react-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
type SearchParamsSyncEmitter
} from './patch-history'

// Abstract the types for the useNavigate hook from react-router-based frameworks
// Abstract away the types for the useNavigate hook from react-router-based frameworks
type NavigateUrl = {
hash?: string
search?: string
Expand All @@ -30,10 +30,6 @@ type UseSearchParams = () => [URLSearchParams, {}]

// --

function getSearchParamsSnapshot() {
return new URLSearchParams(location.search)
}

export function createReactRouterBasedAdapter(
adapter: string,
useNavigate: UseNavigate,
Expand Down Expand Up @@ -82,8 +78,7 @@ export function createReactRouterBasedAdapter(
)
return {
searchParams,
updateUrl,
getSearchParamsSnapshot
updateUrl
}
}
function useOptimisticSearchParams() {
Expand Down
6 changes: 5 additions & 1 deletion packages/nuqs/src/update-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export function enqueueQueryStringUpdate<Value>(
return serializedOrNull
}

function getSearchParamsSnapshotFromLocation() {
return new URLSearchParams(location.search)
}

/**
* Eventually flush the update queue to the URL query string.
*
Expand All @@ -77,7 +81,7 @@ export function enqueueQueryStringUpdate<Value>(
* @returns a Promise to the URLSearchParams that have been applied.
*/
export function scheduleFlushToURL({
getSearchParamsSnapshot = () => new URLSearchParams(location.search),
getSearchParamsSnapshot = getSearchParamsSnapshotFromLocation,
updateUrl,
rateLimitFactor = 1
}: Pick<
Expand Down

0 comments on commit c35fb8c

Please sign in to comment.