{"record":{"id":"597768ddaf1a801a","repo":"facebook/react","slug":"unable-to-find-node-on-an-unmounted-component-597768","errorCode":null,"errorMessage":"Unable to find node on an unmounted component.","messagePattern":"Unable to find node on an unmounted component\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/react-reconciler/src/ReactFiberTreeReflection.js","lineNumber":113,"sourceCode":"      }\n    }\n    if (activityState !== null) {\n      return activityState.dehydrated;\n    }\n  }\n  // TODO: Implement this on ActivityComponent.\n  return null;\n}\n\nexport function getContainerFromFiber(fiber: Fiber): null | Container {\n  return fiber.tag === HostRoot\n    ? (fiber.stateNode.containerInfo as Container)\n    : null;\n}\n\nfunction assertIsMounted(fiber: Fiber) {\n  if (getNearestMountedFiber(fiber) !== fiber) {\n    throw new Error('Unable to find node on an unmounted component.');\n  }\n}\n\nexport function findCurrentFiberUsingSlowPath(fiber: Fiber): Fiber | null {\n  const alternate = fiber.alternate;\n  if (!alternate) {\n    // If there is no alternate, then we only need to check if it is mounted.\n    const nearestMounted = getNearestMountedFiber(fiber);\n\n    if (nearestMounted === null) {\n      throw new Error('Unable to find node on an unmounted component.');\n    }\n\n    if (nearestMounted !== fiber) {\n      return null;\n    }\n    return fiber;\n  }","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/facebook/react/blob/eafeac097ba51e1eab809c07102126bd5f8e5425/packages/react-reconciler/src/ReactFiberTreeReflection.js#L95-L131","documentation":"assertIsMounted is an internal guard used when React reflects over the fiber tree (findCurrentFiberUsingSlowPath and its callers, e.g. findDOMNode-style and findCurrentHostFiber lookups). It requires that the fiber being inspected is itself its nearest mounted fiber, i.e. it is still attached to a mounted HostRoot. Accessing a component or instance whose tree has unmounted makes this invariant fail and React throws rather than return a node from a dead tree.","triggerScenarios":"Calling a reflection API (findDOMNode, findCurrentHostFiber, container lookups built on findCurrentFiberUsingSlowPath) on a fiber whose nearest mounted ancestor is a different fiber — the referenced component unmounted and the fiber is detached from any mounted tree.","commonSituations":"setTimeout/requestAnimationFrame/event callbacks that fire after the component unmounted and still read a DOM node or instance; StrictMode double-mount tests holding fibers from the first pass; Fast Refresh/hot reload keeping stale references; duplicate react + react-dom copies disagreeing about mount state during partial upgrades.","solutions":["Null-check and connectivity-check the ref/instance (ref.current != null && ref.current.isConnected) before touching it","Cancel timers, observers, and event listeners in the useEffect cleanup function so callbacks never run after unmount","Move the read into useEffect/useLayoutEffect scoped to the same component so it runs only while mounted","Verify only one copy/version pair of react and react-dom is loaded (npm ls react react-dom), and upgrade together — some assertIsMounted failures were fixed reconciler bugs"],"exampleFix":"// before\nuseEffect(() => {\n  const t = setTimeout(() => measure(ref.current.getBoundingClientRect()), 100);\n}, []); // no cleanup; ref.current may be null after unmount\n\n// after\nuseEffect(() => {\n  const t = setTimeout(() => {\n    const node = ref.current;\n    if (node != null && node.isConnected) {\n      measure(node.getBoundingClientRect());\n    }\n  }, 100);\n  return () => clearTimeout(t);\n}, []);","handlingStrategy":"validation","validationCode":"function isStillMounted(node) {\n  return node != null && node.isConnected === true;\n}\n// before any imperative lookup\nif (isStillMounted(ref.current)) {\n  const dom = findDOMNodeEquivalent(ref.current);\n}","typeGuard":"function isAttachedElement(node) {\n  return node instanceof Element && node.isConnected;\n}","tryCatchPattern":null,"preventionTips":["Check ref.current is non-null and connected before every deferred DOM/instance access","Cancel timers, observers, and listeners in useEffect cleanup so nothing runs after unmount","Do not cache instances across renders; re-read refs at call time"],"tags":["unmounted","finddomnode","refs","fiber","stale-reference"],"backgroundTag":"unmounted-component-access","analyzedSha":"eafeac097ba51e1eab809c07102126bd5f8e5425","analyzedAt":"2026-08-21T22:01:08.818Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}