On modal mount, push history if current history state doesn't match this modal's id #4144
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves
Proposed Changes
Currently, on modal mount, we adjust the
window.history. Ifhistory.state === null, we push a new history entry; if it's not null, we just replace history.The problem with this is that if we've already navigated within the single page application, say from the project page to editor, then
history.stateis not null; so we just replace history when the library modal is open. Then if the user hits the back button, the browser navigates back to the previoushistoryentry -- in this case, the project page.This change instead checks
history.state === null || history.state !== this.id, which is more permissive; if thehistory.stateentry exists but is not the same as the current view, we push, instead of replacing.Reason for Changes
Browsing was behaving in an unexpected, frustrating way.
Test Coverage
I added a test of the back button functionality, but note that it doesn't actually fail if this code change isn't included. Still, I think it's good to have.
Browser Coverage
Check the OS/browser combinations tested (At least 2)
Mac
Windows
Chromebook
iPad
Android Tablet