47ng / nuqs

Type-safe search params state manager for React frameworks - Like useState, but stored in the URL query string.
https://nuqs.47ng.com
MIT License
4.91k stars 105 forks source link

throttleMs behavior: Immediate first input creates edge case for minimum input validation #713

Closed RomkaLTU closed 1 month ago

RomkaLTU commented 1 month ago

Context

What's your version of nuqs?

"nuqs": "^2.0.4",

What framework are you using?

Which version of your framework are you using?

NextJS 14.2.15

Description

The throttleMs functionality is kind of strange. It will capture the first input instantaneously and then throttle according to the throttleMs parameter. That's pretty much it. This requires additional logic, for example, if you don't want to allow searching with just 1 letter.

RomkaLTU commented 1 month ago

In general, this throttleMs is not good for search text input. If you try to type, the second letter will be skipped. For example, if you try to type 'hello', it will appear as 'hllo'."

franky47 commented 1 month ago

Yes, this is the expected behaviour for throttling: the URL is regularly updated, with an instant initial update.

While this works well for low-frequency UI elements like tabs or check boxes, high frequency ones (and particularly search) would benefit better from a debounce behaviour, where the update is eventually sent after a period of inactivity.

Debounce support is on the roadmap and should land soon, see #291.