This repository was archived by the owner on Nov 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
router: fix for popstate event on page load in Safari #154
Merged
sinan
merged 5 commits into
koding:master
from
alex-ionochkin:tms-2476-safari-router-issue
Mar 9, 2016
Merged
router: fix for popstate event on page load in Safari #154
sinan
merged 5 commits into
koding:master
from
alex-ionochkin:tms-2476-safari-router-issue
Mar 9, 2016
Conversation
This file contains 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
LGTM 👍 |
@blockPopstateIfWindowLoaded = no | ||
else | ||
@blockPopstateIfWindowLoaded = yes | ||
window.addEventListener 'load', @bound 'handleWindowLoad' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
👍 nice catch & fix thx @alex-ionochkin |
@sinan, I agree. Your version is more elegant. However, I'd like to add a few changes:
|
PR is updated |
return yes | ||
startListening: do -> | ||
|
||
readyStateBinded = no |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
readyStateBound
Fixed |
sinan
added a commit
that referenced
this pull request
Mar 9, 2016
router: fix for popstate event on page load in Safari
👍 |
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
popstate
event 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
popstate
right after window is loaded. So we catch this moment and skippopstate
handling. Note that ifpopstate
event is triggered before page is loaded (for example, page is loading slowly and user clicksBack
button) or after that, behavior isn't changed./cc @gokmen