modrinth / code

The Modrinth monorepo containing all code which powers Modrinth!
https://modrinth.com
Other
863 stars 150 forks source link

Browser history in search pagination #1843

Open Ellisthion opened 2 years ago

Ellisthion commented 2 years ago

Environment

No response

Describe the bug

Hitting the browser 'back' button does not allow you to go to a previous page when searching through mods.

Steps To Reproduce

  1. Go to home page
  2. Click search button to go to mods search
  3. Click page 2
  4. Hit browser back button

You end up back on the home page, instead of on page 1 of the search results.

Expected behavior

Expected that you'd go back to the previous page of results.

Additional context

This issue is an unintended side-effect of the fix for modrinth/code#1899, wherein the browser history got spammed. The change for that was all search updates use $router.replace rather than $router.push.

The search can change from 4 different things, all handled by the same js function:

The search text should clearly stay as replace due to the original issue, and whether the dropdowns and filters should be replace or push is debatable and leaving them as replace is fine. However, if the event is triggered by the user changing pages, it should use push to allow the user to back/forward through the pages.

mrmelon54 commented 2 years ago

I have a suggested fix for this. Keep the history not changing the same to prevent spamming the history. But store an internal array of state changes so when pressing the back button in the browser you can replace state back to the previous state. Thus fixing both issues.

SepiaPages commented 1 year ago

I'm not sure if this is actually related but, similarly, I've found that the back button doesn't navigate me away from the project page if I've come from a notification. For example, I click on a notification to go to the new upload, then I hit the back button, it loads briefly but just keeps me on the same page. I have to hold and manually select which page to go back to in order to escape, or spam the back button, in which case it goes back 2 pages and then I'm able to select forward and return to the notifications page.. I'm on Firefox on Windows 10.