Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Setting values via setQueryParams causes page to jump #3836

Closed
nickytonline opened this issue Aug 2, 2024 · 3 comments · Fixed by #3837
Closed

Bug: Setting values via setQueryParams causes page to jump #3836

nickytonline opened this issue Aug 2, 2024 · 3 comments · Fixed by #3837
Assignees

Comments

@nickytonline
Copy link
Member

It's great to store state in the query string instead of component state in a lot of cases, however, our current setQueryParams helper function for this causes the page to jump.

CleanShot 2024-08-02 at 11 33 30

Next.js' router allows you to prevent scrolling, i.e. update the page and scroll back to the top. We should update our helper function to default to false for scrolling.

function setQueryParams(
  params: Record<string, string>,
  paramsToRemove: Array<string> = [],
-  pathname?: string
+  pathname?: string,
+  scroll = false
) {
  const presentQueryParams = deleteKeys(Router.query, paramsToRemove);

  // Merge final query and set URL
  Router.push(
    {
      pathname: pathname || Router.pathname,
      query: {
        ...presentQueryParams,
        ...params,
      },
    },
+   undefined,
+   { scroll }
  );
}
@nickytonline nickytonline added 🐛 bug Something isn't working ux labels Aug 2, 2024
@nickytonline nickytonline self-assigned this Aug 2, 2024
Copy link
Contributor

github-actions bot commented Aug 2, 2024

Thanks for the issue, our team will look into it as soon as possible! If you would like to work on this issue, please wait for us to decide if it's ready. The issue will be ready to work on once we remove the "needs triage" label.

To claim an issue that does not have the "needs triage" label, please leave a comment that says ".take". If you have any questions, please comment on this issue.

For full info on how to contribute, please check out our contributors guide.

Copy link
Contributor

open-sauced bot commented Aug 2, 2024

🎉 This issue has been resolved in version 2.50.0-beta.5 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Copy link
Contributor

open-sauced bot commented Aug 6, 2024

🎉 This issue has been resolved in version 2.50.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@open-sauced open-sauced bot added the released label Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant