Skip to content

Commit

Permalink
be sure that the DOM content is loaded before checking for user defin…
Browse files Browse the repository at this point in the history
…ed camera with querySelectorAll
  • Loading branch information
vincentfretin committed Sep 24, 2022
1 parent d56b570 commit de2e908
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/core/scene/a-scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ var warn = utils.debug('core:a-scene:warn');

if (isIOS) { require('../../utils/ios-orientationchange-blank-bug'); }

/**
* Create a Promise that resolves once the DOM content is loaded.
*
* @returns {Promise}
*/
function waitForDOMContentLoaded () {
if (document.readyState !== 'loading') {
return Promise.resolve(null);
} else {
return new Promise(function (resolve) {
document.addEventListener('DOMContentLoaded', resolve);
});
}
}

/**
* Scene element, holds all entities.
*
Expand Down Expand Up @@ -134,7 +149,11 @@ module.exports.AScene = registerElement('a-scene', {
self.attachedCallbackPostCamera();
});

this.initSystems();
// Some systems use querySelectorAll so we need to be sure the DOM content is loaded.
// For example the camera system is using querySelectorAll to check for user defined
// camera before injecting a default camera, but it fails to find the camera if the
// querySelectorAll is executed before DOMContentLoaded.
waitForDOMContentLoaded().then(this.initSystems.bind(this));

// WebXR Immersive navigation handler.
if (this.hasWebXR && navigator.xr && navigator.xr.addEventListener) {
Expand Down

0 comments on commit de2e908

Please sign in to comment.