Skip to content

Invoking .append() / .set() / .delete() on useSearchParams()[0] on the server has side effects #13493

@depoulo

Description

@depoulo

I'm using React Router as a...

library

Reproduction

This is a follow-up from #11449 (comment)

Go to https://stackblitz.com/edit/github-z7wmgfsy-hdxy35ti?file=app%2Froutes%2Fhome.tsx and follow the instructions.

This is not a URLSearchParams sheanigan, see

node -e "const sp=new URL('http://example.com/?page=1').searchParams;const page=sp.get('page');sp.delete('page');console.log({page})"
# prints { page: '1' }

System Info

Stackblitz

Used Package Manager

npm

Expected Behavior

No hydration mismatch, variable retrieved via .get() from useSearchParams[0] return value is not mutated by later .set() call to the same return value, just like in the Node.js example.

Actual Behavior

Hydration mismatch, invoking .append() / .set() / .delete() on useSearchParams[0] return value mutates variables retrieved earlier in the execution context.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions