DOM Event Propagation (Capture, Target, Bubble)
Three-phase DOM event traversal from window to target and back, enabling single-listener delegation on common ancestors.
About this page
DOM Click Propagation Lifecycle
Trace the event path from window down to <button> and back up.
The engine identifies <button> as event.target at the pointer coordinates.
- eventPhase
- HIT_TEST
- target
- <button>
- currentTarget
- null
Under the Hood#
- Hit-Testing: The engine identifies the deepest element under the pointer (
event.target). - Capture Phase: Walks
window -> document -> html -> ... -> parent, invoking listeners registered with{ capture: true }. - Target & Bubble Phases: Invokes listeners on
target, then walks back up towindow(unlessbubbles: false, such asfocus,blur, orscroll). - Microtask Checkpoint: Between two distinct listeners triggered by a real UI event, the Event Loop drains pending microtasks.
// Single delegated listener handles 1,000 rows without per-row allocations
tableBody.addEventListener('click', (event) => {
const row = event.target.closest('tr[data-row-id]');
if (!row) return;
selectRow(row.dataset.rowId);
});Problem Genealogy#
- 2000 (Incompatible Netscape/IE Models): Capture-only in Netscape, Bubbling-only in Internet Explorer, forcing every library to ship a bespoke event normalizer.
- 2002 (DOM Level 2 Events): Unified three-phase model (
addEventListener(type, fn, useCapture)). - 2015+ (Root Event Delegation in Frameworks): Single listener at the framework root avoiding thousands of per-node listener allocations.
Production Pitfalls#
stopPropagation()breaks analytics and popovers: Halting propagation prevents global listeners (including Popover API light-dismiss or telemetry) from receiving the event.- Non-passive
touchstart/wheellisteners: Without{ passive: true }, the Compositor Thread waits on the main thread before scrolling in casepreventDefault()is called.
Where this connects
Prerequisites
Event Loop, Macrotasks, and Microtask Queue
Each user interaction event is dispatched as a macrotask with a microtask checkpoint after every listener.
Next & related
Async Clipboard API and User Activation
Transient user activation is minted by trusted input events dispatching through the DOM.
The inert Attribute and Modal Focus Containment
Inert subtrees suppress pointer and keyboard event dispatch during hit-testing before propagation.
Passive Event Listeners and Compositor Scrolling
Passive flags are checked during hit-testing before dispatching wheel or touch propagation.
Pointer Events, touch-action, and Pointer Capture
Pointer events follow standard capture/target/bubble propagation unless redirected by setPointerCapture().
Shadow DOM Encapsulation and Event Retargeting
Shadow trees modify event propagation by retargeting event.target to the host at the ShadowRoot.
AbortController and Cooperative Cancellation
Passing an AbortSignal to addEventListener detaches groups of listeners without manual removeEventListener calls.
Seen in Architecture Autopsies
Autopsy #01: Double Payment on a Disabled Button
Two queued click tasks fire before React commits disabled={true} when an await precedes setIsSubmitting(true).
Mechanical Comparisons
- Contrasts WithAbortController and Cooperative Cancellation vs DOM Event Propagation (Capture, Target, Bubble)
Passing an AbortSignal to addEventListener detaches groups of listeners without manual removeEventListener calls.