Skip to content

7.7.0 Breaking behaviour when using useSearchParams setter with previous values #14041

@Querela

Description

@Querela

Reproduction

Change anything in the input text field. In 7.6.3 this automatically updated the search params. Updates to the search params (e.g., initial page load or otherwise) would then automatically be used to set the input text field value.

React.useEffect was used to (a) update the URLSearchParams when an input text field changes and (b) changes of URLSearchParams were observed to updated the same input text field. This was used to generate perma URLs that reflect the input form fields, so users can change the text input field and the URL is up to date and others users can paste the perma URL and have already pre-filled forms.

In react-router version 7.6.3 everything worked as intended. With version 7.7.0 this behaviour changed, probably due to #12784 where the setSearchParams hook receives a copy of the last searchParams which might cause the detection whether something changed to be different.

System Info

System:
    OS: Linux 6.1 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
    CPU: (2) x64 AMD EPYC
    Memory: 2.55 GB / 4.01 GB
    Container: Yes
    Shell: Unknown
  Binaries:
    Node: 20.12.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.5.0 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/share/npm-global/bin/pnpm
  npmPackages:
    react-router: 7.7.0 => 7.7.0 
    vite: ^6.0.3 => 6.0.3

Used Package Manager

pnpm

Expected Behavior

Input field works without issues and changes are possible.

Actual Behavior

Input text field can't be changed.

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