Maintain URL Parameter Order #777
-
It would be beneficial for Nuqs to include a feature that ensures URL query parameters are kept in a consistent order. When adding or modifying query parameters via Nuqs utilities, the order of parameters in the URL should remain consistent and predictable. The order can be based on the useQueryStates object order. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
There was a proposal to sort search params alphabetically in #638, but after playing with it, it felt very unpredictable. See #638 (comment) The current behaviour is in line with URLSearchParams: new keys are appended at the end of the query string, and updates to existing values are done in-place. Doing it such as it follows the order of the object raises the question of what happens when combining multiple useQueryStates or useQueryState updates in one batch, example: const [, set1] = useQueryStates({ a: ..., b: ... })
const [, set2] = useQueryStates({ c: ..., d: ... })
const [, set3] = useQueryState('e')
set3('e')
set2({ c: 'c' })
set1({ b: 'b' }) |
Beta Was this translation helpful? Give feedback.
There was a proposal to sort search params alphabetically in #638, but after playing with it, it felt very unpredictable. See #638 (comment)
The current behaviour is in line with URLSearchParams: new keys are appended at the end of the query string, and updates to existing values are done in-place.
Doing it such as it follows the order of the object raises the question of what happens when combining multiple useQueryStates or useQueryState updates in one batch, example: