Skip to content

feat!: add null to return type of serialize()#1355

Open
CatBraaain wants to merge 1 commit into47ng:nextfrom
CatBraaain:add-null-type-to-serialize-return
Open

feat!: add null to return type of serialize()#1355
CatBraaain wants to merge 1 commit into47ng:nextfrom
CatBraaain:add-null-type-to-serialize-return

Conversation

@CatBraaain
Copy link
Copy Markdown

Allow the serialize() function to return null to support clearing the query parameter, similar to useQueryState.

Background

In useQueryState, null consistently represents the absence of a query parameter:

  • When reading, the returned value is null if the key is not present in the URL.
  • When writing, passing null to the setter removes the key from the query string.

ref:

Example

This change enables parsers to conditionally omit values from the URL. For example, a parser could return null for certain values to keep
the URL clean:

const parser = createParser({
  parse: (value) => parseInt(value),
  serialize: (value) => value === 0 ? null : String(value)
})

When 0 is set, the parameter will be cleared from the URL instead of showing ?key=0.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 9, 2026

@CatBraaain is attempting to deploy a commit to the 47ng Team on Vercel.

A member of the Team first needs to authorize it.

@franky47
Copy link
Copy Markdown
Member

franky47 commented Mar 9, 2026

This seems like a useful addition, but the widening of the return type for serialize is a breaking change (see the failure in the docs build).

I'll keep this one here for the v3 release line.

@franky47 franky47 added this to the v3 milestone Mar 9, 2026
@CatBraaain CatBraaain force-pushed the add-null-type-to-serialize-return branch from 80781e9 to 67c20c4 Compare March 10, 2026 06:30
@CatBraaain CatBraaain force-pushed the add-null-type-to-serialize-return branch from 67c20c4 to 9f8cfb2 Compare March 10, 2026 06:33
@CatBraaain
Copy link
Copy Markdown
Author

Thanks for taking a look.
I see about the breaking change, that makes sense.

I've pushed new commit fixes the type errors and formatting issues.

@franky47 franky47 changed the title feat: add null to return type of serialize() feat!: add null to return type of serialize() Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants