{"action":"created","comment":{"url":"https://api.github.com/repos/yahoo/fluxible/pulls/comments/55780746","id":55780746,"diff_hunk":"@@ -119,22 +137,30 @@ function createComponent(Component, opts) {\n             this._scrollTimer = window.setTimeout(this._saveScrollPosition, 150);\n         },\n         _onHistoryChange: function (e) {\n+            debug('history listener invoked', e);\n+            if (this._ignorePageLoadPopstate) {\n+                // 1) e.state (null) and history.state (not null)\n+                //    -- this is popstate triggered on pageload in Safari browser.\n+                //       history.state is not null, because if _ignorePageLoadPopstate\n+                //       is true, we replaceState in componentDidMount() to set state obj\n+                // 2) e.state(not null) and history.state (not null)\n+                //    -- regular popstate triggered by forward/back button click and history.go(n)\n+                // 3) history.state (null)\n+                //    -- this is not a valid scenario, as we update the state before\n+                //       _onHistoryChange gets invoked in componentDidMount()\n+                var stateFromHistory = this._history.getState();\n+                var isPageloadPopstate = e.state === null && !!stateFromHistory;\n+                debug('history listener detecting pageload popstate', e.state, stateFromHistory);\n+                if (isPageloadPopstate) {\n+                    debug('history listener skipped pageload popstate');\n+                    return;\n+                }\n+            }\n             var props = this.props;\n             var url = this._history.getUrl();\n             var currentRoute = props.currentRoute || {};\n             var nav = props.currentNavigate || {};\n \n-            // Add currentNavigate.externalUrl checking for https://github.com/yahoo/fluxible/issues/349:\n-            // \"Safari popstate issue causing handleHistory.js to execute the navigateAction on page load\".\n-            // This needs app to dispatch \"externalUrl\" as part of the payload for the NAVIGATE_START event\n-            // on server side, which contains the absolute url user sees in browser when the request is made.\n-            // For client side navigation, \"externalUrl\" field is not needed and is not set by fluxible-router.\n-            var externalUrl = nav.externalUrl;\n-            if (externalUrl && externalUrl === window.location.href.split('#')[0]) {\n-                // this is the initial page load, omit the popstate event erroneously fired by Safari browsers.\n-                return;\n-            }\n-","path":"packages/fluxible-router/lib/handleHistory.js","position":88,"original_position":88,"commit_id":"afc4dc585540b28b07919424279de659e87d5f53","original_commit_id":"afc4dc585540b28b07919424279de659e87d5f53","user":{"login":"lingyan","id":1414235,"avatar_url":"https://avatars.githubusercontent.com/u/1414235?v=3","gravatar_id":"","url":"https://api.github.com/users/lingyan","html_url":"https://github.com/lingyan","followers_url":"https://api.github.com/users/lingyan/followers","following_url":"https://api.github.com/users/lingyan/following{/other_user}","gists_url":"https://api.github.com/users/lingyan/gists{/gist_id}","starred_url":"https://api.github.com/users/lingyan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lingyan/subscriptions","organizations_url":"https://api.github.com/users/lingyan/orgs","repos_url":"https://api.github.com/users/lingyan/repos","events_url":"https://api.github.com/users/lingyan/events{/privacy}","received_events_url":"https://api.github.com/users/lingyan/received_events","type":"User","site_admin":false},"body":"the check for `externalUrl` is no longer needed","created_at":"2016-03-11T02:00:54Z","updated_at":"2016-03-11T02:00:54Z","html_url":"https://github.com/yahoo/fluxible/pull/394#discussion_r55780746","pull_request_url":"https://api.github.com/repos/yahoo/fluxible/pulls/394","_links":{"self":{"href":"https://api.github.com/repos/yahoo/fluxible/pulls/comments/55780746"},"html":{"href":"https://github.com/yahoo/fluxible/pull/394#discussion_r55780746"},"pull_request":{"href":"https://api.github.com/repos/yahoo/fluxible/pulls/394"}}},"pull_request":{"url":"https://api.github.com/repos/yahoo/fluxible/pulls/394","id":62487427,"html_url":"https://github.com/yahoo/fluxible/pull/394","diff_url":"https://github.com/yahoo/fluxible/pull/394.diff","patch_url":"https://github.com/yahoo/fluxible/pull/394.patch","issue_url":"https://api.github.com/repos/yahoo/fluxible/issues/394","number":394,"state":"open","locked":false,"title":"allow ignore popstate event on page load, this is mainly a fix for sa…","user":{"login":"lingyan","id":1414235,"avatar_url":"https://avatars.githubusercontent.com/u/1414235?v=3","gravatar_id":"","url":"https://api.github.com/users/lingyan","html_url":"https://github.com/lingyan","followers_url":"https://api.github.com/users/lingyan/followers","following_url":"https://api.github.com/users/lingyan/following{/other_user}","gists_url":"https://api.github.com/users/lingyan/gists{/gist_id}","starred_url":"https://api.github.com/users/lingyan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lingyan/subscriptions","organizations_url":"https://api.github.com/users/lingyan/orgs","repos_url":"https://api.github.com/users/lingyan/repos","events_url":"https://api.github.com/users/lingyan/events{/privacy}","received_events_url":"https://api.github.com/users/lingyan/received_events","type":"User","site_admin":false},"body":"…fari browser, see discussions in issue #349 and PR #351 for more details\r\n\r\n@mridgway @redonkulus @kaesonho \r\ncc: @skippykawakami \r\n\r\nThis PR does not change existing behavior, by introducing the fix behind a feature flag `ignorePopstateOnPageLoad`, with default value `false`.  Most of the apps will not need to enable this.  It is only needed for a special case where the url in currentRoute (in dehydrated RouteStore) is different from what is in the browser, typical due to an intermediate layer like ATS altering url before sending request to origin server.\r\n\r\nThe mechanism of identifying pageload popstate event:\r\n* On Safari browser, when page loads, browser will trigger a popstate event with `null` state (in `event.state`)\r\n* But we can't just check for `event.state === null` of popstate events to say it is triggered by page load, because if you load a new page in a browser, navigate to a new page, and on back button, a popstate event will be triggered, this event's `state` property will be `null`.\r\n* To get around that, we manually replace the history state on page load (in componentDidMount() to be exact).  This way, all pages loaded with fluxible-router or client-navigated with fluxible-router will guarantee to have a non-null history.state object.  So all regular popstate events will guarantee to have a non-null `event.state`.\r\n\r\nWith that, we can use the following logic to tell whether the popstate event is triggered on page load:\r\n```\r\n                var stateFromHistory = this._history.getState();\r\n                var isPageloadPopstate = e.state === null && !!stateFromHistory;\r\n                debug('history listener detecting pageload popstate', e.state, stateFromHistory);\r\n                if (isPageloadPopstate) {\r\n                    debug('history listener skipped pageload popstate');\r\n                    return;\r\n                }\r\n```\r\n\r\nSome other alternatives for this issue is to delay `window.addEventListener('popstate', ...)` to after onload event.  Did not want to go that route, since that could introduce a delay comparing to what is currently supported.\r\n\r\n","created_at":"2016-03-11T02:00:04Z","updated_at":"2016-03-11T02:00:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bac20a7b261894c3ecc7ec874f2b5495f15a3b86","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/yahoo/fluxible/pulls/394/commits","review_comments_url":"https://api.github.com/repos/yahoo/fluxible/pulls/394/comments","review_comment_url":"https://api.github.com/repos/yahoo/fluxible/pulls/comments{/number}","comments_url":"https://api.github.com/repos/yahoo/fluxible/issues/394/comments","statuses_url":"https://api.github.com/repos/yahoo/fluxible/statuses/afc4dc585540b28b07919424279de659e87d5f53","head":{"label":"yahoo:ignorePageLoadPopstate","ref":"ignorePageLoadPopstate","sha":"afc4dc585540b28b07919424279de659e87d5f53","user":{"login":"yahoo","id":16574,"avatar_url":"https://avatars.githubusercontent.com/u/16574?v=3","gravatar_id":"","url":"https://api.github.com/users/yahoo","html_url":"https://github.com/yahoo","followers_url":"https://api.github.com/users/yahoo/followers","following_url":"https://api.github.com/users/yahoo/following{/other_user}","gists_url":"https://api.github.com/users/yahoo/gists{/gist_id}","starred_url":"https://api.github.com/users/yahoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yahoo/subscriptions","organizations_url":"https://api.github.com/users/yahoo/orgs","repos_url":"https://api.github.com/users/yahoo/repos","events_url":"https://api.github.com/users/yahoo/events{/privacy}","received_events_url":"https://api.github.com/users/yahoo/received_events","type":"Organization","site_admin":false},"repo":{"id":26189434,"name":"fluxible","full_name":"yahoo/fluxible","owner":{"login":"yahoo","id":16574,"avatar_url":"https://avatars.githubusercontent.com/u/16574?v=3","gravatar_id":"","url":"https://api.github.com/users/yahoo","html_url":"https://github.com/yahoo","followers_url":"https://api.github.com/users/yahoo/followers","following_url":"https://api.github.com/users/yahoo/following{/other_user}","gists_url":"https://api.github.com/users/yahoo/gists{/gist_id}","starred_url":"https://api.github.com/users/yahoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yahoo/subscriptions","organizations_url":"https://api.github.com/users/yahoo/orgs","repos_url":"https://api.github.com/users/yahoo/repos","events_url":"https://api.github.com/users/yahoo/events{/privacy}","received_events_url":"https://api.github.com/users/yahoo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/yahoo/fluxible","description":"A pluggable container for universal flux applications","fork":false,"url":"https://api.github.com/repos/yahoo/fluxible","forks_url":"https://api.github.com/repos/yahoo/fluxible/forks","keys_url":"https://api.github.com/repos/yahoo/fluxible/keys{/key_id}","collaborators_url":"https://api.github.com/repos/yahoo/fluxible/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/yahoo/fluxible/teams","hooks_url":"https://api.github.com/repos/yahoo/fluxible/hooks","issue_events_url":"https://api.github.com/repos/yahoo/fluxible/issues/events{/number}","events_url":"https://api.github.com/repos/yahoo/fluxible/events","assignees_url":"https://api.github.com/repos/yahoo/fluxible/assignees{/user}","branches_url":"https://api.github.com/repos/yahoo/fluxible/branches{/branch}","tags_url":"https://api.github.com/repos/yahoo/fluxible/tags","blobs_url":"https://api.github.com/repos/yahoo/fluxible/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/yahoo/fluxible/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/yahoo/fluxible/git/refs{/sha}","trees_url":"https://api.github.com/repos/yahoo/fluxible/git/trees{/sha}","statuses_url":"https://api.github.com/repos/yahoo/fluxible/statuses/{sha}","languages_url":"https://api.github.com/repos/yahoo/fluxible/languages","stargazers_url":"https://api.github.com/repos/yahoo/fluxible/stargazers","contributors_url":"https://api.github.com/repos/yahoo/fluxible/contributors","subscribers_url":"https://api.github.com/repos/yahoo/fluxible/subscribers","subscription_url":"https://api.github.com/repos/yahoo/fluxible/subscription","commits_url":"https://api.github.com/repos/yahoo/fluxible/commits{/sha}","git_commits_url":"https://api.github.com/repos/yahoo/fluxible/git/commits{/sha}","comments_url":"https://api.github.com/repos/yahoo/fluxible/comments{/number}","issue_comment_url":"https://api.github.com/repos/yahoo/fluxible/issues/comments{/number}","contents_url":"https://api.github.com/repos/yahoo/fluxible/contents/{+path}","compare_url":"https://api.github.com/repos/yahoo/fluxible/compare/{base}...{head}","merges_url":"https://api.github.com/repos/yahoo/fluxible/merges","archive_url":"https://api.github.com/repos/yahoo/fluxible/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/yahoo/fluxible/downloads","issues_url":"https://api.github.com/repos/yahoo/fluxible/issues{/number}","pulls_url":"https://api.github.com/repos/yahoo/fluxible/pulls{/number}","milestones_url":"https://api.github.com/repos/yahoo/fluxible/milestones{/number}","notifications_url":"https://api.github.com/repos/yahoo/fluxible/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/yahoo/fluxible/labels{/name}","releases_url":"https://api.github.com/repos/yahoo/fluxible/releases{/id}","deployments_url":"https://api.github.com/repos/yahoo/fluxible/deployments","created_at":"2014-11-04T21:25:38Z","updated_at":"2016-03-10T20:45:22Z","pushed_at":"2016-03-11T02:00:04Z","git_url":"git://github.com/yahoo/fluxible.git","ssh_url":"git@github.com:yahoo/fluxible.git","clone_url":"https://github.com/yahoo/fluxible.git","svn_url":"https://github.com/yahoo/fluxible","homepage":"http://fluxible.io","size":1859,"stargazers_count":1481,"watchers_count":1481,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":162,"mirror_url":null,"open_issues_count":32,"forks":162,"open_issues":32,"watchers":1481,"default_branch":"master"}},"base":{"label":"yahoo:master","ref":"master","sha":"21f5f1781287c46a67a6c139be8a33e410938ebb","user":{"login":"yahoo","id":16574,"avatar_url":"https://avatars.githubusercontent.com/u/16574?v=3","gravatar_id":"","url":"https://api.github.com/users/yahoo","html_url":"https://github.com/yahoo","followers_url":"https://api.github.com/users/yahoo/followers","following_url":"https://api.github.com/users/yahoo/following{/other_user}","gists_url":"https://api.github.com/users/yahoo/gists{/gist_id}","starred_url":"https://api.github.com/users/yahoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yahoo/subscriptions","organizations_url":"https://api.github.com/users/yahoo/orgs","repos_url":"https://api.github.com/users/yahoo/repos","events_url":"https://api.github.com/users/yahoo/events{/privacy}","received_events_url":"https://api.github.com/users/yahoo/received_events","type":"Organization","site_admin":false},"repo":{"id":26189434,"name":"fluxible","full_name":"yahoo/fluxible","owner":{"login":"yahoo","id":16574,"avatar_url":"https://avatars.githubusercontent.com/u/16574?v=3","gravatar_id":"","url":"https://api.github.com/users/yahoo","html_url":"https://github.com/yahoo","followers_url":"https://api.github.com/users/yahoo/followers","following_url":"https://api.github.com/users/yahoo/following{/other_user}","gists_url":"https://api.github.com/users/yahoo/gists{/gist_id}","starred_url":"https://api.github.com/users/yahoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yahoo/subscriptions","organizations_url":"https://api.github.com/users/yahoo/orgs","repos_url":"https://api.github.com/users/yahoo/repos","events_url":"https://api.github.com/users/yahoo/events{/privacy}","received_events_url":"https://api.github.com/users/yahoo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/yahoo/fluxible","description":"A pluggable container for universal flux applications","fork":false,"url":"https://api.github.com/repos/yahoo/fluxible","forks_url":"https://api.github.com/repos/yahoo/fluxible/forks","keys_url":"https://api.github.com/repos/yahoo/fluxible/keys{/key_id}","collaborators_url":"https://api.github.com/repos/yahoo/fluxible/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/yahoo/fluxible/teams","hooks_url":"https://api.github.com/repos/yahoo/fluxible/hooks","issue_events_url":"https://api.github.com/repos/yahoo/fluxible/issues/events{/number}","events_url":"https://api.github.com/repos/yahoo/fluxible/events","assignees_url":"https://api.github.com/repos/yahoo/fluxible/assignees{/user}","branches_url":"https://api.github.com/repos/yahoo/fluxible/branches{/branch}","tags_url":"https://api.github.com/repos/yahoo/fluxible/tags","blobs_url":"https://api.github.com/repos/yahoo/fluxible/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/yahoo/fluxible/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/yahoo/fluxible/git/refs{/sha}","trees_url":"https://api.github.com/repos/yahoo/fluxible/git/trees{/sha}","statuses_url":"https://api.github.com/repos/yahoo/fluxible/statuses/{sha}","languages_url":"https://api.github.com/repos/yahoo/fluxible/languages","stargazers_url":"https://api.github.com/repos/yahoo/fluxible/stargazers","contributors_url":"https://api.github.com/repos/yahoo/fluxible/contributors","subscribers_url":"https://api.github.com/repos/yahoo/fluxible/subscribers","subscription_url":"https://api.github.com/repos/yahoo/fluxible/subscription","commits_url":"https://api.github.com/repos/yahoo/fluxible/commits{/sha}","git_commits_url":"https://api.github.com/repos/yahoo/fluxible/git/commits{/sha}","comments_url":"https://api.github.com/repos/yahoo/fluxible/comments{/number}","issue_comment_url":"https://api.github.com/repos/yahoo/fluxible/issues/comments{/number}","contents_url":"https://api.github.com/repos/yahoo/fluxible/contents/{+path}","compare_url":"https://api.github.com/repos/yahoo/fluxible/compare/{base}...{head}","merges_url":"https://api.github.com/repos/yahoo/fluxible/merges","archive_url":"https://api.github.com/repos/yahoo/fluxible/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/yahoo/fluxible/downloads","issues_url":"https://api.github.com/repos/yahoo/fluxible/issues{/number}","pulls_url":"https://api.github.com/repos/yahoo/fluxible/pulls{/number}","milestones_url":"https://api.github.com/repos/yahoo/fluxible/milestones{/number}","notifications_url":"https://api.github.com/repos/yahoo/fluxible/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/yahoo/fluxible/labels{/name}","releases_url":"https://api.github.com/repos/yahoo/fluxible/releases{/id}","deployments_url":"https://api.github.com/repos/yahoo/fluxible/deployments","created_at":"2014-11-04T21:25:38Z","updated_at":"2016-03-10T20:45:22Z","pushed_at":"2016-03-11T02:00:04Z","git_url":"git://github.com/yahoo/fluxible.git","ssh_url":"git@github.com:yahoo/fluxible.git","clone_url":"https://github.com/yahoo/fluxible.git","svn_url":"https://github.com/yahoo/fluxible","homepage":"http://fluxible.io","size":1859,"stargazers_count":1481,"watchers_count":1481,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":162,"mirror_url":null,"open_issues_count":32,"forks":162,"open_issues":32,"watchers":1481,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/yahoo/fluxible/pulls/394"},"html":{"href":"https://github.com/yahoo/fluxible/pull/394"},"issue":{"href":"https://api.github.com/repos/yahoo/fluxible/issues/394"},"comments":{"href":"https://api.github.com/repos/yahoo/fluxible/issues/394/comments"},"review_comments":{"href":"https://api.github.com/repos/yahoo/fluxible/pulls/394/comments"},"review_comment":{"href":"https://api.github.com/repos/yahoo/fluxible/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/yahoo/fluxible/pulls/394/commits"},"statuses":{"href":"https://api.github.com/repos/yahoo/fluxible/statuses/afc4dc585540b28b07919424279de659e87d5f53"}}}}