This repository was archived by the owner on Nov 25, 2020. It is now read-only.
router: fix for popstate event on page load in Safari#154
Merged
sinan merged 5 commits intokoding:masterfrom Mar 9, 2016
Merged
router: fix for popstate event on page load in Safari#154sinan merged 5 commits intokoding:masterfrom
sinan merged 5 commits intokoding:masterfrom
Conversation
Contributor
|
LGTM 👍 |
| @blockPopstateIfWindowLoaded = no | ||
| else | ||
| @blockPopstateIfWindowLoaded = yes | ||
| window.addEventListener 'load', @bound 'handleWindowLoad' |
Member
There was a problem hiding this comment.
I think, if you only edit ::startListenining as below it would be cleaner and enough.
startListening: ->
return no if @isListening # make this action idempotent
# Safari fires extra popstate event right after window is loaded
# this is to avoid this inconsistent initial firing
unless document.readyState is 'complete'
return document.onreadystatechange = =>
@startListening() if document.readyState is 'complete'
@isListening = yes
window.addEventListener 'popstate', @bound "popState"
return yes
Member
|
👍 nice catch & fix thx @alex-ionochkin |
Contributor
Author
|
@sinan, I agree. Your version is more elegant. However, I'd like to add a few changes:
|
Contributor
Author
|
PR is updated |
| return yes | ||
| startListening: do -> | ||
|
|
||
| readyStateBinded = no |
Contributor
Author
|
Fixed |
sinan
added a commit
that referenced
this pull request
Mar 9, 2016
router: fix for popstate event on page load in Safari
Member
|
👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
@sinan, can you please review this fix?
Currently we have a problem that Safari fires
popstateevent after the page is loaded. In some cases it causes double rendering since router handler is called one more time.This issue is mentioned on MDN (https://developer.mozilla.org/ru/docs/Web/Events/popstate):
The idea of this fix is taken from here - http://stackoverflow.com/a/18126524. The most important thing here is that Safari fires
popstateright after window is loaded. So we catch this moment and skippopstatehandling. Note that ifpopstateevent is triggered before page is loaded (for example, page is loading slowly and user clicksBackbutton) or after that, behavior isn't changed./cc @gokmen