Skip to content

multi→single search-param unset does not commit RSC #93104

Closed

Description

@dave-wwg

Link to the code that reproduces this issue

https://github.com/dave-wwg/next-multi-value-searchparam-repro

To Reproduce

I've generated a test suite which demonstrates this bug

pnpm install
pnpm dev            # starts on :3100
# in another shell:
pnpm exec playwright install chromium
pnpm exec playwright test

You can also re-produce manually by:

  1. loading localhost:3100
  2. toggling each of the 2 filters on, incrementing the count by 1 each time
  3. toggling one of the filters off, which does not decrement the count as expected

Current vs. Expected behavior

Current

When router.replace(url, { scroll: false }) changes a repeated search-param from multiple values (?k=A&k=B) to a single value (?k=B), the new RSC payload is fetched and the server renders with the correct searchParams, but the client tree never commits the update. The server-rendered JSX and the client component's server-passed props stay stale. Other transitions on the same param (empty→single, single→multi) commit correctly — only multi→single is broken. It also seems to work if the toggle is done a second time?

here are the logs pulled from my browser console.

Server  [server] f.status = [] count = 0
toggles.tsx:20 [client] props.count = 0 props.values = [] url.values = []
installHook.js:1 [client] props.count = 0 props.values = [] url.values = []
host-console-events.js:1 [client] props.count = 0 props.values = [] url.values = []
host-console-events.js:1 [client] props.count = 0 props.values = [] url.values = []
host-console-events.js:1  Server  [server] f.status = ["A"] count = 1
host-console-events.js:1 [client] props.count = 1 props.values = ["A"] url.values = ["A"]
host-console-events.js:1 [client] props.count = 1 props.values = ["A"] url.values = ["A"]
host-console-events.js:1 [client] props.count = 1 props.values = ["A"] url.values = ["A"]
host-console-events.js:1 [client] props.count = 1 props.values = ["A"] url.values = ["A"]
host-console-events.js:1  Server  [server] f.status = ["A","B"] count = 2
host-console-events.js:1 [client] props.count = 2 props.values = ["A","B"] url.values = ["A","B"]
host-console-events.js:1 [client] props.count = 2 props.values = ["A","B"] url.values = ["A","B"]
host-console-events.js:1 [client] props.count = 2 props.values = ["A","B"] url.values = ["A","B"]
host-console-events.js:1 [client] props.count = 2 props.values = ["A","B"] url.values = ["A","B"]
host-console-events.js:1 [client] props.count = 2 props.values = ["A","B"] url.values = ["B"]
host-console-events.js:1 [client] props.count = 2 props.values = ["A","B"] url.values = ["B"]
host-console-events.js:1  Server  [server] f.status = ["B"] count = 1

they are missing the client logs which should say:

[client] props.count = 1 props.values = ["B"] url.values = ["B"]
host-console-events.js:1 [client] props.count = 1 props.values = ["B"] url.values = ["B"]

Expected

The client tree always responds to data updates

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.3.0: Wed Jan 28 20:53:31 PST 2026; root:xnu-12377.81.4~5/RELEASE_ARM64_T8122
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 22.14.0
  npm: 10.9.2
  Yarn: 1.22.22
  pnpm: 10.29.2
Relevant Packages:
  next: 16.2.4 // Latest available version is detected (16.2.4).
  eslint-config-next: N/A
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.9.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

React

Which stage(s) are affected? (Select all that apply)

next dev (local), next start (local)

Additional context

full disclosure, this re-production was generated by Claude Code! But spun out of a real bug i found in my code. I took a look at the minimal re-pro and it seems like it should be working

Activity

  1. added theissue type on Apr 21, 2026
  2. added
    React
    on Apr 21, 2026
  3. Ingole712521 commented on Apr 22, 2026

    @Ingole712521

    I was able to reproduce this consistently, and it does look like a framework-level issue rather than a problem with the user code.

    From debugging, it seems that during a multi → single transition (e.g. ?k=A&k=B → ?k=B), the server correctly renders the new state and the RSC payload is fetched, but the client tree doesn’t commit the update. The URL reflects the new value, but the client component continues to receive stale props. Other transitions (empty → single, single → multi) behave as expected.

    As a temporary workaround, forcing a client refresh right after the navigation makes the state consistent again:

    router.replace(url, { scroll: false })
    router.refresh()

    Alternatively, forcing a remount via a key derived from the search params also avoids the issue:

    <MyComponent key={(searchParams.k ?? []).join(",")} ... />

    Both approaches essentially bypass the stale tree reuse and ensure the new RSC payload is applied.

    This suggests the issue might be related to how the App Router determines cache identity or reuses the existing tree when repeated search params shrink from multiple values to a single value.

    Happy to help test any fixes or provide more logs if needed

  4. dave-wwg commented on Apr 22, 2026

    @dave-wwg
    Author

    @Ingole712521 , i actually wasn't able to successfully force a remount using key. can you share a more complete example, perhaps based on my example repro code?

  5. mlev commented on Apr 22, 2026

    @mlev

    Same for me - I couldn't force a remount. As per OP I can see the RSC request is made and correct data is returned but component doesn't re-render.

    I think the cause is identified here: #92787 - but this issue is much easier to find!

  6. NiteshCodes7 commented on Apr 23, 2026

    @NiteshCodes7

    I tried solving this issue. Please let me know after reviewing it.
    Link for the pull request I created - #93154 (comment)

    Closes #93104

    What's happening

    When navigating from ?k=A&k=B (multi-value) to ?k=B (single-value) via router.replace(), the client tree never commits the update — props stay stale even though the server renders correctly.

    Root cause

    In createSegmentFromRouteTree inside ppr-navigations.ts, the client builds a segment cache key from the current renderedSearch string:

    // Before (buggy)
    const stringifiedQuery = JSON.stringify(
      Object.fromEntries(new URLSearchParams(renderedSearch))
    )

    Object.fromEntries on a URLSearchParams with repeated keys silently drops all but the last value. This means:

    • ?k=A&k=B → { k: "B" } → __PAGE__?{"k":"B"}
    • ?k=B → { k: "B" } → __PAGE__?{"k":"B"}

    Both produce the same segment key, so matchSegment treats them as identical, the stale cache node is reused, and the client never re-renders with the new props.

    This explains the asymmetric behavior reported in the issue:

    • empty → single ✅ (keys are genuinely different)
    • single → multi ✅ (keys are genuinely different)
    • multi → single ❌ (keys wrongly collide due to Object.fromEntries)
    • "works on second toggle" ✅ (by then currentRenderedSearch has caught up so the comparison path differs)

    Fix

    Use getAll() to preserve repeated values, matching exactly what the server does in addSearchParamsIfPageSegment:

    // After (fixed)
    const urlSearchParams = new URLSearchParams(renderedSearch)
    const queryObj: Record<string, string | string[]> = {}
    for (const key of new Set(urlSearchParams.keys())) {
      const vals = urlSearchParams.getAll(key)
      queryObj[key] = vals.length === 1 ? vals[0] : vals
    }
    const stringifiedQuery = JSON.stringify(queryObj)

    Now:

    • ?k=A&k=B → { k: ["A", "B"] } → __PAGE__?{"k":["A","B"]}
    • ?k=B → { k: "B" } → __PAGE__?{"k":"B"}

    These are distinct keys, the cache node is correctly replaced, and the client commits the updated props.

    Testing

    Reproduction repo from the issue: https://github.com/dave-wwg/next-multi-value-searchparam-repro

    The existing playwright test suite in that repo passes after this fix (it was designed to fail when the bug is present).

  7. marcoshernanz commented on Aug 25, 2026

    @marcoshernanz
    Contributor

    Thanks for the report. This was fixed in #94863 and shipped in Next.js 16.3.0. I confirmed the repro fails on 16.2.12 and passes on 16.3.0, 16.3.3, and the current canary, including a production run on 16.3.3. Please upgrade to 16.3 or newer. Closing as fixed.

  8. github-actions commented on Sep 10, 2026

    @github-actions
    Contributor

    This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

  9. locked as resolved and limited conversation to collaborators on Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Reactlocked

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions