-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ssr): check for window and document
- Loading branch information
1 parent
03c01c6
commit e3e8c85
Showing
2 changed files
with
24 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,26 @@ | ||
export function checkReady() { | ||
const DEVICE_READY_TIMEOUT = 5000; | ||
if (typeof process === 'undefined') { | ||
const win: any = typeof window !== 'undefined' ? window : {}; | ||
const DEVICE_READY_TIMEOUT = 5000; | ||
|
||
// To help developers using cordova, we listen for the device ready event and | ||
// log an error if it didn't fire in a reasonable amount of time. Generally, | ||
// when this happens, developers should remove and reinstall plugins, since | ||
// an inconsistent plugin is often the culprit. | ||
const before = Date.now(); | ||
// To help developers using cordova, we listen for the device ready event and | ||
// log an error if it didn't fire in a reasonable amount of time. Generally, | ||
// when this happens, developers should remove and reinstall plugins, since | ||
// an inconsistent plugin is often the culprit. | ||
const before = Date.now(); | ||
|
||
let didFireReady = false; | ||
document.addEventListener('deviceready', () => { | ||
console.log(`Ionic Native: deviceready event fired after ${Date.now() - before} ms`); | ||
didFireReady = true; | ||
}); | ||
let didFireReady = false; | ||
win.document.addEventListener('deviceready', () => { | ||
console.log(`Ionic Native: deviceready event fired after ${Date.now() - before} ms`); | ||
didFireReady = true; | ||
}); | ||
|
||
setTimeout(() => { | ||
if (!didFireReady && window.cordova) { | ||
console.warn( | ||
`Ionic Native: deviceready did not fire within ${DEVICE_READY_TIMEOUT}ms. This can happen when plugins are in an inconsistent state. Try removing plugins from plugins/ and reinstalling them.` | ||
); | ||
} | ||
}, DEVICE_READY_TIMEOUT); | ||
setTimeout(() => { | ||
if (!didFireReady && win.cordova) { | ||
console.warn( | ||
`Ionic Native: deviceready did not fire within ${DEVICE_READY_TIMEOUT}ms. This can happen when plugins are in an inconsistent state. Try removing plugins from plugins/ and reinstalling them.` | ||
); | ||
} | ||
}, DEVICE_READY_TIMEOUT); | ||
} | ||
} |
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