Skip to content

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

@diarmidmackenzie

Description

@diarmidmackenzie

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions