Skip to content

Commit

Permalink
wait for DOMContentLoaded before initializing components on entity
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentfretin committed Oct 1, 2022
1 parent 29115f9 commit 4aef7d8
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/core/a-entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,21 @@ var proto = Object.create(ANode.prototype, {
// Don't .load() scene on attachedCallback.
if (this.isScene) { return; }

// Gracefully not error when outside of <a-scene> (e.g., tests).
if (!sceneEl) {
this.load();
return;
}
utils.waitForDOMContentLoaded().then(function () {
// Gracefully not error when outside of <a-scene> (e.g., tests).
if (!sceneEl) {
self.load();
return;
}

// Wait for asset management system to finish before loading.
assetsEl = sceneEl.querySelector('a-assets');
if (assetsEl && !assetsEl.hasLoaded) {
assetsEl.addEventListener('loaded', function () { self.load(); });
return;
}
this.load();
// Wait for asset management system to finish before loading.
assetsEl = sceneEl.querySelector('a-assets');
if (assetsEl && !assetsEl.hasLoaded) {
assetsEl.addEventListener('loaded', function () { self.load(); });
return;
}
self.load();
});
}
},

Expand Down

0 comments on commit 4aef7d8

Please sign in to comment.