How to Debug React Portals

React Portals allow you to render child components into a DOM node that exists outside the DOM hierarchy of the parent component. While highly useful for modals, tooltips, and dropdowns, their split nature—existing in one place in the React virtual tree and another in the physical DOM—can make debugging challenging. This article explains how to efficiently debug React Portals using React Developer Tools, browser DOM inspectors, and event bubbling analysis.

Inspecting the React Component Tree vs. the DOM Tree

When debugging portals, you must distinguish between the React virtual tree and the HTML DOM tree:

Using React Developer Tools

The React Developer Tools browser extension is the most effective tool for inspecting a portal’s state, props, and context.

  1. Open your browser’s Developer Tools and navigate to the Components tab.
  2. Use the search bar or navigate the tree to find the parent component that renders the portal.
  3. In the tree, you will see a node explicitly labeled Portal.
  4. Expand the Portal node to see the rendered child components.
  5. Select the components inside the portal to inspect their active state, props, hooks, and context in the right-hand panel.

Locating Portals in the Browser DOM Inspector

If you need to debug CSS styling, positioning, or layout issues, you must inspect the actual DOM tree.

  1. Open the browser’s Elements (or Inspector) tab.
  2. Scroll to the bottom of the HTML document or locate the designated portal container element (e.g., <div id="portal-root">).
  3. If the portal closes automatically when you try to inspect it (common with hover-triggered tooltips), trigger the portal, then pause JavaScript execution. In Chrome, press F8 or Ctrl + \ (Windows) / Cmd + \ (Mac) while in the Sources panel to freeze the UI, allowing you to inspect the portal DOM without it disappearing.
  4. Alternatively, right-click the target container in the Elements tab, select Break on, and choose Subtree modifications to trigger a breakpoint the moment the portal is inserted into the DOM.

Troubleshooting Event Bubbling

React Portals bubble events up the React virtual tree, not the physical DOM tree. If an event handler is not firing:

Ensuring the Target DOM Node Exists

A frequent runtime error when working with portals is Target container is not a DOM element. To debug this: