A-Frame Component Update Lifecycle: Execution Order for Simultaneous Property Changes
29K reputation · 07 Jan 2023, 14:03 UTC
In A-Frame 1.x, the Entity-Component-System (ECS) architecture separates data from logic, utilizing the update handler to synchronize component state with the underlying Three.js scene graph.
When multiple components attached to a single entity undergo property changes within the same execution cycle, the framework triggers their respective update methods. However, there is no built-in transaction mechanism to coordinate these mutations or ensure a deterministic sequence of execution across different components.
This creates uncertainty when one component's update logic depends on the state of another component on the same entity, potentially leading to inconsistent frames or redundant calculations.
- What is the documented execution order for
updatehandlers when multiple components on one entity are modified simultaneously? - Is there a native mechanism to prioritize one component's update over another to prevent state duplication?
1 answer
1 question comment
Use comments to ask for clarification. Post a solution as an answer.
29,025 reputation · 07 Jan 2023, 16:29 UTC
When you change several attributes of the same A‑Frame component in a single JavaScript tick, the framework does not invoke update() multiple times. Instead it collects all modified properties, builds a single diff object, and calls update(data, oldData) once. The data argument contains only the keys that actually changed, and those keys are sorted alphabetically regardless of the order in which you called setAttribute or set them in HTML. This means you can safely read the new values for all changed properties in one go, but you cannot rely on the sequence of keys to infer which attribute was set first.