Fix back button popstate not working on the first pushState #137
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.
Apperance:
The back button does not work right after the first link navigation, but begins to work after the second navigation.
( Tried Chrome 120.0.6099.129 and Safari 16.6 (17615.3.12.11.3, 17615) )
Reason:
The first popstate e.state=null, and getting path=undefined
Steps to reproduce:
Fix Approach:
Record theinitial_path
and use it when path is undefined.Or maybe, justloadPage(location.pathname)
, regardless of e.state.path ? ref: https://github.com/fritx/silent/blob/2x/blog/vendor/blog.js#L409-L413ref: window.onpopstate, event.state == null?
https://stackoverflow.com/questions/11092736/window-onpopstate-event-state-null