fix(ssr): check for window and document
This commit is contained in:
parent
03c01c687e
commit
e3e8c85087
@ -1,23 +1,26 @@
|
|||||||
export function checkReady() {
|
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
|
// 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,
|
// 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
|
// when this happens, developers should remove and reinstall plugins, since
|
||||||
// an inconsistent plugin is often the culprit.
|
// an inconsistent plugin is often the culprit.
|
||||||
const before = Date.now();
|
const before = Date.now();
|
||||||
|
|
||||||
let didFireReady = false;
|
let didFireReady = false;
|
||||||
document.addEventListener('deviceready', () => {
|
win.document.addEventListener('deviceready', () => {
|
||||||
console.log(`Ionic Native: deviceready event fired after ${Date.now() - before} ms`);
|
console.log(`Ionic Native: deviceready event fired after ${Date.now() - before} ms`);
|
||||||
didFireReady = true;
|
didFireReady = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (!didFireReady && window.cordova) {
|
if (!didFireReady && win.cordova) {
|
||||||
console.warn(
|
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.`
|
`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);
|
}, DEVICE_READY_TIMEOUT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,9 +20,10 @@ export function getPromise<T>(callback: (resolve: Function, reject?: Function) =
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (window.angular) {
|
if (typeof window !== 'undefined' && window.angular) {
|
||||||
|
const doc = window.document;
|
||||||
const injector = window.angular
|
const injector = window.angular
|
||||||
.element(document.querySelector('[ng-app]') || document.body)
|
.element(doc.querySelector('[ng-app]') || doc.body)
|
||||||
.injector();
|
.injector();
|
||||||
if (injector) {
|
if (injector) {
|
||||||
const $q = injector.get('$q');
|
const $q = injector.get('$q');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user