Skip to content

Commit

Permalink
Revert "Merge branch 'master' of https://github.com/yangmingshan/history
Browse files Browse the repository at this point in the history
 into yangmingshan-master"

This reverts commit 54e8948.
  • Loading branch information
mjackson committed Sep 11, 2019
1 parent 54e8948 commit 8bbace1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
22 changes: 4 additions & 18 deletions modules/DOMUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,10 @@ export function supportsGoWithoutReloadUsingHash() {
}

/**
* Returns true if a given popstate event is an extraneous WebKit event,
* or it fired on initial page load (the solution is from page.js [https://github.com/visionmedia/page.js]).
* Returns true if a given popstate event is an extraneous WebKit event.
* Accounts for the fact that Chrome on iOS fires real popstate events
* containing undefined state when pressing the back button.
*/
export const shouldIgnorePopstateEvent = (() => {
let loaded = false;
if (document.readyState === 'complete') {
loaded = true;
} else {
window.addEventListener('load', () =>
setTimeout(() => {
loaded = true;
})
);
}
return event =>
(event.state === undefined &&
navigator.userAgent.indexOf('CriOS') === -1) ||
!loaded;
})();
export function isExtraneousPopstateEvent(event) {
return event.state === undefined && navigator.userAgent.indexOf('CriOS') === -1;
}
5 changes: 3 additions & 2 deletions modules/createBrowserHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
getConfirmation,
supportsHistory,
supportsPopStateOnHashChange,
shouldIgnorePopstateEvent
isExtraneousPopstateEvent
} from './DOMUtils.js';
import invariant from './invariant.js';
import warning from './warning.js';
Expand Down Expand Up @@ -86,7 +86,8 @@ function createBrowserHistory(props = {}) {
}

function handlePopState(event) {
if (shouldIgnorePopstateEvent(event)) return;
// Ignore extraneous popstate events in WebKit.
if (isExtraneousPopstateEvent(event)) return;
handlePop(getDOMLocation(event.state));
}

Expand Down

0 comments on commit 8bbace1

Please sign in to comment.