-
-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Empty query not returning expected value #648
Comments
IMO this behavior makes more sense. Its empty then its empty. the example of |
Yes, this was the original behaviour, and after discussion in #329 we changed it to an empty array. |
I understand it make some sense, but it doesn't represent the true state of the url because |
Okej yeah that is a bit of an annoying edge case, I feel your pain 😔 Maybe it should be some middle ground? Like an option that can be passed in so that it can be used for both cases? |
There are two different cases here:
For point n°1, if you wish to have a different behaviour, there's always the option to fork the code of the For point n°2, PRs are welcome. |
for point 1 that's what I did. copy paste the implementation you had for |
I fully agree with point 1, the current behavior makes sense. And for point 2, I would be down to make a PR. The behavior would be that |
@imMatheus I think the following might make sense, if we follow the behaviour of individual parsers: // URL: ?name=,123
const [str] = useQueryState('name', parseAsArrayOf(parseAsString))
const [strDef] = useQueryState('name', parseAsArrayOf(parseAsString.withDefault('foo')))
const [int] = useQueryState('name', parseAsArrayOf(parseAsInteger))
const [intDef] = useQueryState('name', parseAsArrayOf(parseAsInteger.withDefault(42)))
// str: [null, '123']
// strDef: ['foo', '123']
// int: [null, 123]
// intDef: [42, 123] Introducing nulls is not great, but if we don't have a default value, I don't see how we can do otherwise, aside from stripping them off the array. Typing this correctly is going to be fun 🙃 |
Makes sense! Is it okej if I give it a stab in trying to make a PR for this behavior then? :) |
Let's see what the community thinks of it first: https://x.com/fortysevenfx/status/1838931586676318369 |
Context
What's your version of
nuqs
?Next.js information (obtained by running
next info
):Are you using:
basePath
option in your Next.js configwindowHistorySupport
flag in your Next.js configDescription
Based on the documentation:
When having an array of strings define like this in the useQueryState:
And a query like this in the browser:
?ids=
I expect ids to be:
['']
instead I receive:
[]
this happens because of (https://github.com/47ng/nuqs/issues/329). But in my opinion this should have never been approved since at the moment there's no way to represent empty value.
Possible solution can be have 2 parsers, one called parseAsNonEmptyArrayOf (name is an example, i'm sure there is a better name for it), and that returns "" if query is there but no value is there
The text was updated successfully, but these errors were encountered: