aframevr / aframevr/aframe

Silent failure where components not initialized if they are modified immediately after object creation.

Open
#4,973 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
17.6k
Forks
4.4k
PR merge metrics
No merged PRs in 30d

Description

Description:

A problem that I have hit, which may be due to A-Frame restrictions around entity creation, but it would be good to at least get a clear error message when making unsupported API calls, rather than (as currently happens) getting a silent failure to initialize the component.

I have a very simple bit of code that is creating an entity and applying a component to it. However, after appending the entity to the scene (before it has initialized), it may further modify the attributes on the entity, as per the example below.

(this example is simplified: in my case the last 2 lines of code occur in a different context, where it's less obvious the component may still be initializing).

When it does this, no error messages are generated, but the component initialization never actually happens at all.

          const box = document.createElement('a-box');
          box.setAttribute('make-red', '');
          this.el.appendChild(box);
          box.removeAttribute('make-red');
          box.setAttribute('make-red', '');

It would be ideal if these further attributes updates could be processed and applied when the component initializes. However I recognize this may not be possible.

I note the docs here do say that operations after appendChild() and before initialization completes, are limited:
https://aframe.io/docs/1.2.0/introduction/javascript-events-dom-apis.html#adding-an-entity-with-appendchild

"we can’t do many operations on the entity (such as calling .getAttribute()"

Assuming that setAttribute() is forbidden as well as getAttribute(), it would be great to do a couple of things:

  • Could we generate an explicit error message on this setAttribute() call, rather than just silently failing? That would have helped me to track down the problem a lot faster.
  • Can we update the docs to clarify that setAttribute() is disallowed, as well as getAttribute().

I'd be happy to work on a PR for the above, if you agree it would be a worthwhile change to make.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Glitch reproduction and the documentation section on adding an entity with appendChild(), then trace the setAttribute() calls made before initialization completes. Done means the behavior is handled with an explicit error or documented limitation, and the relevant documentation clearly states whether setAttribute() is supported during that period.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.