Skip to content

Empty query not returning expected value #648

Open
@fedediaz-deliverect

Description

@fedediaz-deliverect

Context

What's your version of nuqs?

"nuqs": "^1.19.2"

Next.js information (obtained by running next info):

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.1.0: Mon Oct  9 21:32:11 PDT 2023; root:xnu-10002.41.9~7/RELEASE_ARM64_T6030
  Available memory (MB): 18432
  Available CPU cores: 11
Binaries:
  Node: 20.14.0
  npm: 10.7.0
  Yarn: 1.22.22
  pnpm: 8.15.5
Relevant Packages:
  next: 14.2.10 // There is a newer version (14.2.13) available, upgrade recommended!
  eslint-config-next: 14.2.4
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.3.3
Next.js Config:
  output: standalone
 ⚠ There is a newer version (14.2.13) available, upgrade recommended!
   Please try the latest canary version (`npm install next@canary`) to confirm the issue still exists before creating a new issue.
   Read more - https://nextjs.org/docs/messages/opening-an-issue

Are you using:

  • ✅ The app router
  • ❌ The pages router
  • ❌ The basePath option in your Next.js config
  • ❌ The experimental windowHistorySupport flag in your Next.js config

Description

Based on the documentation:
Screenshot 2024-09-25 at 14 25 25

When having an array of strings define like this in the useQueryState:

const [ids, setIds] = useQueryState(
   "ids"
    parseAsArrayOf(parseAsString).withOptions({ shallow: false, scroll: false, clearOnDefault: true }),
  );

And a query like this in the browser:
?ids=

I expect ids to be:
['']

instead I receive:
[]

Screenshot 2024-09-25 at 14 20 07

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already existsparsers/built-inRelated to built-in parsers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions