-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: avoid using the problematic beforeunload event (#344)
* fix: avoid using the problematic beforeunload event * Account for pageshow happenning after initialisation * Add tests for pageshow/pagehide handling * refactor: use page-lifecycle library * Remove this._hasSetScrollRestoration * simplify logic for saving/restoring scroll restoration * reset scrollRestoration before each test * Fix initialization of variable to happen before it is used * correct assertion * cover case of page initialisation hapenning after scroll ehavior initialisation * update comment * dedupe deps * format Co-authored-by: Jimmy Jia <tesrin@gmail.com>
- Loading branch information
1 parent
e4c9af4
commit 6a7a8b4
Showing
5 changed files
with
102 additions
and
22 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
let listener; | ||
|
||
export const setEventListener = (eventType, callback) => { | ||
listener = callback; | ||
}; | ||
|
||
export const triggerEvent = (oldState, newState) => { | ||
if (listener) { | ||
const event = new Event('statechange'); | ||
event.newState = newState; | ||
event.oldState = oldState; | ||
listener(event); | ||
} | ||
}; |
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