Salesforce Certified Platform Developer II free question 6 / 10 · Domain 3: User Interface
An Aura application event is fired, and no handler in the capture or bubble phase calls stopPropagation() or preventDefault(). Which statement about the handlers in the default phase matches the Developer Guide?
- They are called from the component that fired the event upward, nearest component first
- They are called from the root node through its subtree, in a non-deterministic order
- They are called one at a time in the order in which the handlers were registered
- They are called from the application root down to the component that fired the event, in containment order
Show the answer and explanation
Answer: B
Why this is correct
The "Application Event Propagation" page says that in the default phase, event handlers are invoked in a non-deterministic order from the root node through its subtree. The default phase doesn't have the same propagation rules related to component hierarchy as the capture and bubble phases. If the event's propagation wasn't stopped in a previous phase, the root node defaults to the application root. If it was stopped, the root node is the component whose handler invoked event.stopPropagation().
Why the other options are wrong
"They are called from the component that fired the event upward, nearest component first" … Handlers are invoked from the source component up to the application root in the bubble phase. The default phase has no such hierarchy rule.
"They are called from the application root down to the component that fired the event, in containment order" … Handlers are invoked from the application root down to the source component in the capture phase. The default phase's order is non-deterministic.
"They are called one at a time in the order in which the handlers were registered" … The page says handlers in the default phase run in a non-deterministic order, so they don't follow the order of registration.
Cancelling the default phase
Any registered handler in the capture or bubble phase can cancel the default behavior of the event by calling event.preventDefault(), which prevents execution of any of the handlers in the default phase. The page says the default phase can be useful for handling application events that affect components in different sub-trees of your app.