# AbortController and Cooperative Cancellation vs DOM Event Propagation (Capture, Target, Bubble)

- **Canonical URL:** https://frontend.rocks/vs/abortcontroller-cancellation-vs-dom-event-propagation/
- **Relation:** Contrasts With
- **Last Verified:** 2026-11-15
- **Verdict:** Passing an AbortSignal to addEventListener detaches groups of listeners without manual removeEventListener calls.

## Comparison Matrix

| Dimension | AbortController and Cooperative Cancellation | DOM Event Propagation (Capture, Target, Bubble) |
| :--- | :--- | :--- |
| **Maturity** | Baseline · Widely | Baseline · Widely |
| **Domain** | JS Runtime | DOM & Events |
| **Mental Model** | Kill-switch for in-flight fetch calls, DOM listeners, and async tasks you should have stopped three renders ago—without boolean isMounted flags. | Three-phase DOM event traversal from window to target and back, enabling single-listener delegation on common ancestors. |
| **Prerequisites** | Promises and async/await Internals (Aborted async APIs reject their pending Promises with signal.reason on the Microtask Queue.); Memory Leaks, Retainers, and Detached DOM Trees (Passing { signal } to addEventListener detaches listeners in bulk without retaining callback refs.) | None |
| **When Not to Use** | When not to use a single shared AbortSignal: Never share one global signal across short-lived tasks; create per-operation controllers and compose with AbortSignal.any(). | When not to use bubbling delegation: Events that do not bubble (mouseenter, mouseleave, focus, blur) require focusin/focusout or Capture-phase listeners, and bulk teardown is cleaner via AbortController { signal } options. |

## AbortController and Cooperative Cancellation — Under the Hood
Blink and V8 implement `AbortController` and `AbortSignal` as a paired C++ capability boundary: `controller.abort()` mutates the signal's aborted state once and synchronously invokes every registered abort algorithm. Multiple subsystems can subscribe to `AbortSignal`, yet only the `AbortController` holder can trip them all.

1. **Capability Split**: Consumers receive only `signal` and cannot accidentally abort sibling work.
2. **Idempotent Transition**: Calling `abort(reason)` flips `signal.aborted` once, stores `signal.reason`, and executes registered C++ abort algorithms.
3. **Composition**: `AbortSignal.any([a, b])` and `AbortSignal.timeout(ms)` combine user cancellation with deadlines without manual `clearTimeout`.

```js
let activeCtrl;
async function search(query) {
  activeCtrl?.abort();
  activeCtrl = new AbortController();
  const signal = AbortSignal.any([activeCtrl.signal, AbortSignal.timeout(4000)]);
  const res = await fetch(`/search?q=${encodeURIComponent(query)}`, { signal });
  return res.json();
}
```

## DOM Event Propagation (Capture, Target, Bubble) — Under the Hood
1. **Hit-Testing**: The engine identifies the deepest element under the pointer (`event.target`).
2. **Capture Phase**: Walks `window -> document -> html -> ... -> parent`, invoking listeners registered with `{ capture: true }`.
3. **Target & Bubble Phases**: Invokes listeners on `target`, then walks back up to `window` (unless `bubbles: false`, such as `focus`, `blur`, or `scroll`).
4. **Microtask Checkpoint**: Between two distinct listeners triggered by a real UI event, the [Event Loop](/concepts/event-loop-tasks-microtasks) drains pending microtasks.

```js
// 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);
});
```

## Interactive Labs & Dissections
- [AbortController and Cooperative Cancellation Lab](https://frontend.rocks/concepts/abortcontroller-cancellation/#lab) ([Markdown](https://frontend.rocks/concepts/abortcontroller-cancellation.md))
- [DOM Event Propagation (Capture, Target, Bubble) Lab](https://frontend.rocks/concepts/dom-event-propagation/#lab) ([Markdown](https://frontend.rocks/concepts/dom-event-propagation.md))

## Related Architecture Autopsies
- [Autopsy #01: Anatomy of a Double Payment in Production](https://frontend.rocks/autopsies/double-payment-race-condition/) ([Markdown](https://frontend.rocks/autopsies/double-payment-race-condition.md)): Rapid double-click or 3G network blip charges the user twice despite a disabled={isSubmitting} React button.
- [Autopsy #02: Anatomy of a Memory Leak on an 8-Hour Dashboard](https://frontend.rocks/autopsies/eight-hour-spa-memory-leak/) ([Markdown](https://frontend.rocks/autopsies/eight-hour-spa-memory-leak.md)): SPA operations dashboard climbs from 120 MB to 2.4 GB RAM over an 8-hour shift and crashes with Aw, Snap!
- [Autopsy #13: The useEffect Dependency Loop That DDoSed Our Own API](https://frontend.rocks/autopsies/useeffect-dependency-loop-ddos/) ([Markdown](https://frontend.rocks/autopsies/useeffect-dependency-loop-ddos.md)): Changing a single URL filter triggers an infinite render loop, Maximum update depth exceeded, and a burst of 429 Too Many Requests responses.

## Primary Sources
- https://dom.spec.whatwg.org/#interface-abortcontroller
- https://developer.mozilla.org/en-US/docs/Web/API/AbortController
- https://dom.spec.whatwg.org/#dispatching-events
- https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Event_bubbling
