Skip to content

Commit 924dc00

Browse files
committed
Fix issue when the el.hasLoaded flag can be true but not all components have initialized. A init method of a component might check the flag and assume all components have initialized
1 parent 61f6442 commit 924dc00

File tree

7 files changed

+30
-10
lines changed

7 files changed

+30
-10
lines changed

src/core/a-entity.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ class AEntity extends ANode {
404404
var name;
405405
var componentsToUpdate = this.componentsToUpdate;
406406

407-
if (!this.hasLoaded) { return; }
407+
if (!this.hasLoaded && !this.sceneEl) { return; }
408408

409409
// Gather mixin-defined components.
410410
for (i = 0; i < this.mixinEls.length; i++) {
@@ -511,7 +511,7 @@ class AEntity extends ANode {
511511
var key;
512512

513513
// Already playing.
514-
if (this.isPlaying || !this.hasLoaded) { return; }
514+
if (this.isPlaying || (!this.hasLoaded && !this.sceneEl)) { return; }
515515
this.isPlaying = true;
516516

517517
// Wake up all components.

src/core/a-node.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ class ANode extends HTMLElement {
145145
}
146146
});
147147

148-
self.hasLoaded = true;
149148
self.setupMutationObserver();
150149
if (cb) { cb(); }
150+
self.hasLoaded = true;
151151
self.emit('loaded', undefined, false);
152152
});
153153
}

src/core/component.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ Component.prototype = {
278278

279279
// Just cache the attribute if the entity has not loaded
280280
// Components are not initialized until the entity has loaded
281-
if (!el.hasLoaded) {
281+
if (!el.hasLoaded && !el.sceneEl) {
282282
this.updateCachedAttrValue(attrValue);
283283
return;
284284
}

tests/components/animation.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ suite('animation', function () {
1010
setup(function (done) {
1111
this.done = false;
1212
el = entityFactory();
13-
el.setAttribute('animation', '');
1413
el.addEventListener('componentinitialized', function handler (evt) {
1514
if (evt.detail.name !== 'animation' || this.done) { return; }
1615
component = el.components.animation;
1716
this.done = true;
1817
el.removeEventListener('componentinitialized', handler);
1918
done();
2019
});
20+
el.setAttribute('animation', '');
2121
});
2222

2323
suite('basic animation', () => {

tests/components/line.test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ suite('line', function () {
99
setup(function (done) {
1010
var count = 0;
1111
el = this.el = entityFactory();
12-
el.setAttribute('line', '');
13-
el.setAttribute('line__suffix', '');
14-
if (el.hasLoaded) { done(); }
1512
el.addEventListener('componentinitialized', function (evt) {
1613
if (evt.detail.name !== 'line' &&
1714
evt.detail.name !== 'line__suffix') { return; }
@@ -22,6 +19,8 @@ suite('line', function () {
2219
done();
2320
}
2421
});
22+
el.setAttribute('line', '');
23+
el.setAttribute('line__suffix', '');
2524
});
2625

2726
suite('init', function () {

tests/components/vive-controls.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ suite('vive-controls', function () {
1717
controlsSystem = el.sceneEl.systems['tracked-controls-webvr'];
1818
done();
1919
});
20-
el.setAttribute('vive-controls', 'hand: right; model: false'); // To ensure index = 0.
20+
el.setAttribute('vive-controls', 'hand: right; model: true'); // To ensure index = 0.
2121
});
2222

2323
suite('checkIfControllerPresent', function () {

tests/core/a-entity.test.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,27 @@ suite('a-entity', function () {
121121
}
122122
});
123123

124+
test('entity has not loaded until all components have loaded', function (done) {
125+
const parentEl = el;
126+
const el2 = document.createElement('a-entity');
127+
registerComponent('test', {
128+
schema: {array: {type: 'array'}},
129+
init: function () {
130+
assert.notOk(this.el.hasLoaded);
131+
this.el.addEventListener('loaded', function () {
132+
assert.ok(el2.components.geometry);
133+
assert.ok(el2.components.material);
134+
assert.ok(el2.components.test);
135+
done();
136+
});
137+
}
138+
});
139+
el2.setAttribute('geometry', 'primitive:plane');
140+
el2.setAttribute('test', '');
141+
el2.setAttribute('material', 'color:blue');
142+
parentEl.appendChild(el2);
143+
});
144+
124145
suite('attachedCallback', function () {
125146
test('initializes 3D object', function (done) {
126147
elFactory().then(el => {
@@ -169,7 +190,7 @@ suite('a-entity', function () {
169190
this.sinon.spy(AEntity.prototype, 'play');
170191

171192
el2.addEventListener('play', function () {
172-
assert.ok(el2.hasLoaded);
193+
assert.ok(!el2.hasLoaded && el2.sceneEl);
173194
sinon.assert.called(AEntity.prototype.play);
174195
done();
175196
});

0 commit comments

Comments
 (0)