lila
lila copied to clipboard
Game analysis pollutes browser history
Steps to reproduce
- Go to analysis board. You can analyze a previously played game, or an empty board. User login has no effect.
- Navigate through a bunch of moves.
- View your browser history. You will notice dozens of entries.
A case for improvement
While, this is not necessarily the end of the world, I believe just having a single link to the game would be better. Why?
- If you analyze a bunch of moves from multiple games in a single session, your browser history has hundreds of entries. Instead, having a single link to the game would be more useful.
So,
https://lichess.org/FWxN3GO3
instead of,
https://lichess.org/FWxN3GO3#1
https://lichess.org/FWxN3GO3#2
https://lichess.org/FWxN3GO3#3
https://lichess.org/FWxN3GO3#4
...
- Some URLs don't provide useful information. Additionally, in the case of an empty analysis board, the URLs don't have any meaning.
https://lichess.org/analysis#1
https://lichess.org/analysis#2
...
If this doesn't require extensive knowledge of the codebase, but is recognized as an issue, and is fixable, I am willing to work on it and send a PR.
Thank you for your time.
I personally agree with fixing this but I also want to point out that it is a more general issue where multiple versions of the same page are added to browser history if the string after the hash changes.
For example, when browsing Wikipedia and using the Table of Contents to navigate to different sections of the same article, one would also end up with all of this in their browser history. Also, some websites update the part after the #
in the URL simply while scrolling through an article, and you end up with a couple entries in the browser history just by scrolling through the article.
I followed the steps to reproduce, and it only generated one browser history entry. Which is the intended and expected behavior since the code specifically uses window.history.replaceState
https://github.com/lichess-org/lila/blob/fe6505a845a975939597e323c6a887dfb521faf8/ui/analyse/src/ctrl.ts#L349
This is reproducible in my Windows machine. Using both Chrome and Firefox.
@ornicar you might have navigated through the moves too quickly. There is a slight delay, at least on my system, after which the history is registered. Around 0.5s. Moving through moves too quickly doesn't seem to register it in history.
Additionally, this is only a problem in the game analysis and not the game viewer. So, it is a problem in https://lichess.org/SBP0gEcZ
but not in https://lichess.org/SBP0gEcZgHOw
You can check the address bar, the URL changes from ....#1
to ...#2
with a slight delay. Navigating moves after the URL has changed registers it in history.
The code seems correct though. Both window.history.replaceState()
and location.replace()
don't work here surprisingly.
Browser is up-to-date, windows is updated, and tested with no browser extensions.
Edit: On further inspection, it seems like both window.history.replaceState
and location.replace
don't change the history entries. They replace the history stack (what happens when you press back), but don't change the browser's history entries.
I am able to reproduce this both on Chrome 104.0.5112.81 (Official Build) (64-bit)
and Edge Version 104.0.1293.47 (Official build) (64-bit)
. When reproducing, check that the URL changes each time you go to the next/previous move. If you iterate really quickly over the moves you won't get a changed url until the last move.
From MDN:
history.replaceState() operates exactly like history.pushState(), except that replaceState() modifies the current history entry instead of creating a new one. Note that this doesn't prevent the creation of a new entry in the global browser history.
Also seems like this is a 10 year old issue according to this