Under The Hood
frontend react React 17 / 18 / 19

SyntheticEvent Root Delegation vs Native DOM Dispatch

Last updated
Prerequisites:
DOM Event bubbling and capturing
EventTarget.addEventListener
  • react
  • synthetic-event
  • event-delegation
  • dom
  • bubbling
  • performance

Read at your depth

The practical view

React wraps browser native events in a cross-browser `SyntheticEvent` wrapper. In React 17+, React no longer attaches event listeners to the global `document` node; instead, it delegates and attaches all event listeners to the root DOM container (e.g. `<div id="root">`) where `createRoot()` was mounted. Calling `e.stopPropagation()` stops bubbling within the React virtual tree.

The same idea in other frameworks

react equivalent
Root container event delegation (`container.addEventListener`).

Legacy vs modern

Direct DOM Listener vs React SyntheticEvent Delegation

Direct DOM listeners attach per-node causing memory bloat; React delegates listeners to the root container.

before → after
Per-Element Native Listener
elements.forEach(el => el.addEventListener('click', handler)); // ❌ Thousands of listener allocations
React Delegated SyntheticEvent
<li onClick={() => handleClick(item.id)}>{item.name}</li> // ✅ NEW: Delegated to #root

Interview gotchas

Context

Interviewers test your knowledge of React's multi-version coexistence and architecture evolution.

The mechanical answer

In React 16, all synthetic events were attached to `document`. This broke multi-version micro-frontends and nested non-React libraries because calling `e.stopPropagation()` in an inner tree didn't prevent outer `document` listeners from firing. In React 17+, event listeners are attached to the **root DOM container** (the element passed to `createRoot`), allowing multiple independent React roots to safely coexist on the same page.

Trap

Do not say that React attaches event listeners directly to individual DOM elements like `<button>`. Everything is delegated to the root container.

Under The Hood — a multi-depth technical interview hub.

Third-party licenses Press ⌘ K to search.