{"record":{"id":"5153cd6796278f05","repo":"facebook/react","slug":"364","errorCode":"364","errorMessage":"Invalid host root specified. Should be either a React container or a node with a testname attribute.","messagePattern":"Invalid host root specified\\. Should be either a React container or a node with a testname attribute\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/react-reconciler/src/ReactTestSelectors.js","lineNumber":124,"sourceCode":"export function createTextSelector(text: string): TextSelector {\n  return {\n    $$typeof: TEXT_TYPE,\n    value: text,\n  };\n}\n\nexport function createTestNameSelector(id: string): TestNameSelector {\n  return {\n    $$typeof: TEST_NAME_TYPE,\n    value: id,\n  };\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;","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/facebook/react/blob/eafeac097ba51e1eab809c07102126bd5f8e5425/packages/react-reconciler/src/ReactTestSelectors.js#L106-L142","documentation":"React's test-selector layer (findAllNodes and friends, used by DevTools and www-style testing tooling) resolves the host root you pass to a fiber root via findFiberRootForHostRoot. If the node maps to a React instance, the contract additionally requires that instance to carry a string data-testname prop; when memoizedProps['data-testname'] is missing or not a string, the root is rejected (error code 364).","triggerScenarios":"Calling a test-selector API (e.g. findAllNodes) with a host root that is a React container but whose container element was rendered without a data-testname attribute, so the instance lookup succeeds while the testname check fails.","commonSituations":"Using www-derived test-selector tooling outside the environment where containers always get data-testname; querying document.body when the attribute lives on the app container div; attributes added after render so memoizedProps never saw them.","solutions":["Render into an element that already has data-testname set (e.g. <div id='app' data-testname='root'> in the HTML) before calling selector APIs","Pass the exact container element you gave to createRoot, not an ancestor like document.body","If you did not mean to use test selectors, use the regular DOM/container APIs instead of the test-selector entry points"],"exampleFix":"// before\nconst root = document.getElementById('app'); // <div id='app'></div>\ncreateRoot(root).render(<App />);\nfindAllNodes(document.body, [createTestNameSelector('feed')]); // no data-testname anywhere\n\n// after\n// index.html: <div id='app' data-testname='root'></div>\nconst root = document.getElementById('app');\ncreateRoot(root).render(<App />);\nfindAllNodes(root, [createTestNameSelector('feed')]);","handlingStrategy":"validation","validationCode":"const isTestNameRoot = (el) =>\n  el instanceof Element &&\n  typeof el.getAttribute('data-testname') === 'string';\nif (!isTestNameRoot(hostRoot)) {\n  throw new TypeError('host root needs data-testname before test-selector queries');\n}","typeGuard":"function isTestNameRoot(el) {\n  return el instanceof Element && typeof el.getAttribute('data-testname') === 'string';\n}","tryCatchPattern":null,"preventionTips":["Set data-testname on the container element in the HTML before createRoot mounts","Pass the exact createRoot container, not document.body or an ancestor","Add the attribute before render so it lands in memoizedProps"],"tags":["test-selectors","devtools","find-all-nodes","data-testname"],"backgroundTag":"invalid-test-selector-root","analyzedSha":"eafeac097ba51e1eab809c07102126bd5f8e5425","analyzedAt":"2026-08-21T22:01:08.818Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}