aframevr / aframe

:a: Web framework for building virtual reality experiences.
https://aframe.io/
MIT License
16.66k stars 3.97k forks source link

Components added to primitives before appending to DOM are ignored. #2303

Closed donmccurdy closed 7 years ago

donmccurdy commented 7 years ago

This fails:

var cylinder = document.createElement('a-cylinder');
cylinder.setAttribute('color', '#000000');
cylinder.setAttribute('height', `1.5`);
cylinder.setAttribute('position', `3 1 0`);
scene.appendChild(cylinder);

But this works:

var cylinder = document.createElement('a-cylinder');
scene.appendChild(cylinder);
cylinder.setAttribute('color', '#000000');
cylinder.setAttribute('height', `1.5`);
cylinder.setAttribute('position', `3 1 0`);

Preferably both would work. Seems like a strange edge case that new users could easily be surprised by; I know the primitive init cycle is a bit troublesome but hopefully we can fix this case.

dmarcos commented 7 years ago

Yep, both cases should work

takahirox commented 7 years ago

On my environment, both works.

At Hello world example https://aframe.io/aframe/examples/boilerplate/hello-world/

I ran this on console

var scene = document.querySelector('a-scene')

var cylinder = document.createElement('a-cylinder');
cylinder.setAttribute('color', '#888888');
cylinder.setAttribute('height', '1.5');
cylinder.setAttribute('position', '3 1 0');
scene.appendChild(cylinder);

var cylinder2 = document.createElement('a-cylinder');
scene.appendChild(cylinder2);
cylinder2.setAttribute('color', '#888888');
cylinder2.setAttribute('height', '1.5');
cylinder2.setAttribute('position', '-3 1 0');

Result

image

Have I missed something?

donmccurdy commented 7 years ago

Hm I filed based on this conversation.

But I can't reproduce the problem either. There were websockets involved, so probably the elements were added after scene init, but even so I can't reproduce this.

ngokevin commented 7 years ago

I guess she was on 0.3.2