Skip to content

Commit 300bd31

Browse files
committed
ref: remove debounce + shallow: true warning
1 parent ee31253 commit 300bd31

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

errors/NUQS-422.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
# Invalid Options Combination.
22

3-
This warning will show up if you combine `shallow: true` (the default) and `limitUrlUpdates: debounce` options.
3+
This warning did show up between versions `nuqs@>=2.6.0 && nuqs@<=2.7.2` if you combined `shallow: true` (the default) and `limitUrlUpdates: debounce` options.
44

5-
Debounce only makes sense for server-side data fetching, the returned client state is always updated **immediately**, so combining `limitUrlUpdates: debounce` with `shallow: true` will not work as expected.
5+
The initial argument was that:
66

7-
If you are fetching client-side, you’ll want to debounce the state returned by the hooks instead (using a 3rd party `useDebounce` utility hook).
7+
> Debounce only made sense for server-side data fetching, the returned client state is always updated **immediately**, so combining `limitUrlUpdates: debounce` with `shallow: true` will not work as expected.
8+
>
9+
> If you are fetching client-side, you’ll want to debounce the state returned by the hooks instead (using a 3rd party `useDebounce` utility hook).
810
9-
## Solution
11+
However, debounce _does_ have a purpose even in shallow routing: **reducing history bloat**.
1012

11-
- Set `shallow: false` to allow debounce to work properly, check the [documentation](https://nuqs.dev/docs/options#debounce) for more information.
13+
While nuqs uses `history: replace` by default to avoid polluting your history **stack** (the one you navigate with the Back & Forward browser buttons), every URL update is recorded in the browser's **global history** (that you access via a menu, like `⌘ Y`).
14+
15+
Debouncing gives you finer control over how this global history is populated, with the trade-off of a less reactive URL.
16+
17+
Regardless, debounce only applies to URL updates, so the recommendation for client-side fetching still stands: you'll likely want to debounce the returned state in userland before feeding it to TanStack Query, SWC, tRPC or other tools.

packages/nuqs/src/adapters/next/impl.app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export function NavigationSpy() {
6161

6262
export function useNuqsNextAppRouterAdapter(): AdapterInterface {
6363
const router = useRouter()
64-
const searchParams = useSearchParams() ?? new URLSearchParams()
64+
const searchParams = useSearchParams()
6565
const [optimisticSearchParams, setOptimisticSearchParams] =
6666
useOptimistic<URLSearchParams>(searchParams)
6767
const updateUrl: UpdateUrlFunction = useCallback((search, options) => {

packages/nuqs/src/lib/errors.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ export const errors = {
33
404: 'nuqs requires an adapter to work with your framework.',
44
409: 'Multiple versions of the library are loaded. This may lead to unexpected behavior. Currently using `%s`, but `%s` (via the %s adapter) was about to load on top.',
55
414: 'Max safe URL length exceeded. Some browsers may not be able to accept this URL. Consider limiting the amount of state stored in the URL.',
6-
422: 'Invalid options combination: `limitUrlUpdates: debounce` should be used in SSR scenarios, with `shallow: false`',
76
429: 'URL update rate-limited by the browser. Consider increasing `throttleMs` for key(s) `%s`. %O',
87
500: "Empty search params cache. Search params can't be accessed in Layouts.",
98
501: 'Search params cache already populated. Have you called `parse` twice?'

packages/nuqs/src/useQueryStates.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
import type { Nullable, Options, UrlKeys } from './defs'
88
import { compareQuery } from './lib/compare'
99
import { debug } from './lib/debug'
10-
import { error } from './lib/errors'
1110
import { debounceController } from './lib/queues/debounce'
1211
import { defaultRateLimit } from './lib/queues/rate-limiting'
1312
import {
@@ -323,9 +322,6 @@ export function useQueryStates<KeyMap extends UseQueryStatesKeysMap>(
323322
limitUrlUpdates?.method === 'debounce' ||
324323
parser.limitUrlUpdates?.method === 'debounce'
325324
) {
326-
if (update.options.shallow === true) {
327-
console.warn(error(422))
328-
}
329325
const timeMs =
330326
callOptions?.limitUrlUpdates?.timeMs ??
331327
limitUrlUpdates?.timeMs ??

0 commit comments

Comments
 (0)