Skip to content

[NEXT-1147] Scroll position is reset when search params are updated #49087

Closed
@benjaminwaterlot

Description

@benjaminwaterlot

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Next.js `13.3.5-canary.2`

Link to the code that reproduces this issue

https://codesandbox.io/p/sandbox/modest-gould-h4nlvd?file=%2Fapp%2Fpage.tsx&selection=%5B%7B%22endColumn%22%3A1%2C%22endLineNumber%22%3A7%2C%22startColumn%22%3A1%2C%22startLineNumber%22%3A7%7D%5D

To Reproduce

  • Click the counter to update client state.
  • Scroll a little.
  • Click the second button to update search params.
  • The client state is preserved, but the scroll position is lost.

Describe the Bug

Context

In Next <= 13.2.4, updating search params was working as intended : client state was kept, and scroll position was kept too.

In Next 13.2.5, a regression made the client components unmount and remount when search params were updated.

@feedthejim fixed that unmounting in #49047 (it's testable on 13.3.5-canary.2), but there is still an issue now: scroll position is lost on search params updates.

Problem: persisting state in search params is very important with the App router - that's a clean way for client components to request updated data from the RSC.

Reproduction Codesandbox

Here's a codesandbox reproducing the bug:

https://codesandbox.io/p/sandbox/modest-gould-h4nlvd?file=%2Fapp%2Fpage.tsx&selection=%5B%7B%22endColumn%22%3A1%2C%22endLineNumber%22%3A7%2C%22startColumn%22%3A1%2C%22startLineNumber%22%3A7%7D%5D

In video

CleanShot.2023-05-02.at.14.18.36-converted.mp4

A real-world example of the problem

Previously, the "name for the fund", kept in client state, was reset when updating the sliders. It's now better, but the scroll position reset is still awkward.

CleanShot.2023-05-02.at.14.31.38.mp4

Expected Behavior

When updating search params, the scroll position should be preserved.

Which browser are you using? (if relevant)

Latest stable Google Chrome

How are you deploying your application? (if relevant)

No response

NEXT-1147

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue was opened via the bug report template.linear: nextConfirmed issue that is tracked by the Next.js team.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions