{"record":{"id":"7ceabaaedf203294","repo":"react/react","slug":"devtools-tooltip-root-node-not-found-can-t-displa","errorCode":null,"errorMessage":"DevTools tooltip root node not found: can't display the context menu","messagePattern":"DevTools tooltip root node not found: can't display the context menu","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/react-devtools-shared/src/devtools/ContextMenu/useContextMenu.js","lineNumber":50,"sourceCode":"  }, []);\n\n  useEffect(() => {\n    const anchor = anchorElementRef.current;\n    if (anchor == null) return;\n\n    function handleAnchorContextMenu(e: MouseEvent) {\n      e.preventDefault();\n      e.stopPropagation();\n\n      const {pageX, pageY} = e;\n\n      const ownerDocument = anchor?.ownerDocument;\n      const portalContainer = ownerDocument?.querySelector(\n        '[data-react-devtools-portal-root]',\n      );\n\n      if (portalContainer == null) {\n        throw new Error(\n          \"DevTools tooltip root node not found: can't display the context menu\",\n        );\n      }\n\n      // `x` and `y` should be relative to the container, to which these context menus will be portaled\n      // we can't use just `pageX` or `pageY` for Fusebox integration, because RDT frontend is inlined with the whole document\n      // meaning that `pageY` will have an offset of 27, which is the tab bar height\n      // for the browser extension, these will equal to 0\n      const {top: containerTop, left: containerLeft} =\n        portalContainer.getBoundingClientRect();\n\n      setShouldShow(true);\n      setPosition({x: pageX - containerLeft, y: pageY - containerTop});\n    }\n\n    anchor.addEventListener('contextmenu', handleAnchorContextMenu);\n    return () => {\n      anchor.removeEventListener('contextmenu', handleAnchorContextMenu);","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/react/react/blob/22e4f993c7ce9373c95aef093b003f84249e2045/packages/react-devtools-shared/src/devtools/ContextMenu/useContextMenu.js#L32-L68","documentation":"useContextMenu queries the document for [data-react-devtools-portal-root] on every contextmenu event so the menu can be portaled into it. If that node is absent the menu has nowhere to mount, so it throws. The portal root is injected by the DevTools shell (browser extension content script, standalone, or Fusebox inline).","triggerScenarios":"Right-clicking an anchor element after the DevTools portal root was removed from the DOM, or before the DevTools shell has injected it.","commonSituations":"DevTools shell not finished initialising when the user right-clicks; a custom DevTools embedding that forgot to render <div data-react-devtools-portal-root />; Fusebox/inline integration where the portal node was unmounted with the panel.","solutions":["Ensure the DevTools shell renders <div data-react-devtools-portal-root /> into the host document before any context menu can open.","If embedding DevTools yourself, add the portal root node to ownerDocument.body and keep it mounted for the session.","Gate the contextmenu listener on the portal root existing."],"exampleFix":"// before — embedding without a portal root\n// (menu throws on right-click)\n\n// after — inject the portal root the DevTools shell expects\nconst root = document.createElement('div');\nroot.setAttribute('data-react-devtools-portal-root', '');\ndocument.body.appendChild(root);","handlingStrategy":"validation","validationCode":"// Ensure the DevTools portal root exists before the menu can open.\nfunction ensurePortalRoot(doc) {\n  let node = doc.querySelector('[data-react-devtools-portal-root]');\n  if (!node) {\n    node = doc.createElement('div');\n    node.setAttribute('data-react-devtools-portal-root', '');\n    doc.body.appendChild(node);\n  }\n  return node;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always render <div data-react-devtools-portal-root /> in the host document when embedding DevTools.","Delay enabling context-menu listeners until the portal root is present.","Keep the portal root mounted for the entire DevTools session."],"tags":["context-menu","portal-root","dom","devtools-shell","embedding"],"backgroundTag":null,"analyzedSha":"22e4f993c7ce9373c95aef093b003f84249e2045","analyzedAt":"2026-08-12T22:33:25.580Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}