{"record":{"id":"57b75acaebd09cb4","repo":"facebook/react","slug":"362","errorCode":"362","errorMessage":"Could not find React container within specified host subtree.","messagePattern":"Could not find React container within specified host subtree\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/react-reconciler/src/ReactTestSelectors.js","lineNumber":135,"sourceCode":"  };\n}\n\nfunction findFiberRootForHostRoot(hostRoot: Instance): Fiber {\n  const maybeFiber = getInstanceFromNode(hostRoot as any);\n  if (maybeFiber != null) {\n    if (typeof maybeFiber.memoizedProps['data-testname'] !== 'string') {\n      throw new Error(\n        'Invalid host root specified. Should be either a React container or a node with a testname attribute.',\n      );\n    }\n\n    return maybeFiber as any as Fiber;\n  } else {\n    const fiberRoot = findFiberRoot(hostRoot);\n\n    // $FlowFixMe[invalid-compare]\n    if (fiberRoot === null) {\n      throw new Error(\n        'Could not find React container within specified host subtree.',\n      );\n    }\n\n    // The Flow type for FiberRoot is a little funky.\n    // createFiberRoot() cheats this by treating the root as :any and adding stateNode lazily.\n    return (fiberRoot as any).stateNode.current as Fiber;\n  }\n}\n\nfunction matchSelector(fiber: Fiber, selector: Selector): boolean {\n  const tag = fiber.tag;\n  switch (selector.$$typeof) {\n    case COMPONENT_TYPE:\n      if (fiber.type === selector.value) {\n        return true;\n      }\n      break;","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/facebook/react/blob/eafeac097ba51e1eab809c07102126bd5f8e5425/packages/react-reconciler/src/ReactTestSelectors.js#L117-L153","documentation":"In findFiberRootForHostRoot, when getInstanceFromNode finds no React instance on the host root, React falls back to findFiberRoot to locate a container in the node's subtree. A null result means the node is neither a React container nor contains one (error code 362), so React cannot reflect from that node into the fiber tree at all.","triggerScenarios":"Calling test-selector APIs such as findAllNodes on a DOM node that React never rendered into — a wrong node, a different document/iframe/shadow root, or a container that was never mounted.","commonSituations":"Querying before createRoot(container).render() has mounted; passing an element from another iframe or jsdom window than the one React rendered into; querying after unmount severed the container link; typos in test selector roots.","solutions":["Call the test-selector API only after createRoot(container).render(...) has mounted (wrap tests in act/await)","Pass the exact element you handed to createRoot, from the same document React rendered into","Check the element is connected to the document (isConnected) before querying"],"exampleFix":"// before\nconst container = document.createElement('div'); // never rendered into\nfindAllNodes(container, [createTestNameSelector('feed')]); // throws: no container in subtree\n\n// after\nconst container = document.createElement('div');\ndocument.body.appendChild(container);\ncreateRoot(container).render(<App />);\nawait act(() => {}); // let React mount\nfindAllNodes(container, [createTestNameSelector('feed')]);","handlingStrategy":"validation","validationCode":"const isReactContainer = (el) =>\n  el instanceof Element &&\n  Object.keys(el).some((k) => k.startsWith('__reactContainer') || k.startsWith('_reactRootContainer'));\n// query only after React owns the container\nif (isReactContainer(containerEl)) {\n  findAllNodes(containerEl, selectors);\n}","typeGuard":"function isReactContainer(el) {\n  return el instanceof Element &&\n    Object.keys(el).some((k) => k.startsWith('__reactContainer'));\n}","tryCatchPattern":null,"preventionTips":["Call test-selector APIs only after createRoot(...).render(...) completes (await act in tests)","Use the exact container element from the same document React rendered into","Verify el.isConnected before querying to skip detached subtrees"],"tags":["test-selectors","devtools","container","find-all-nodes"],"backgroundTag":"invalid-test-selector-root","analyzedSha":"eafeac097ba51e1eab809c07102126bd5f8e5425","analyzedAt":"2026-08-21T22:01:08.818Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}