{"record":{"id":"9b37812fbcd7198c","repo":"facebook/react","slug":"unable-to-find-node-on-an-unmounted-component","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/ReactFiberReconciler.js","lineNumber":164,"sourceCode":"\n  const fiber = getInstance(parentComponent);\n  const parentContext = findCurrentUnmaskedContext(fiber);\n\n  if (fiber.tag === ClassComponent) {\n    const Component = fiber.type;\n    if (isLegacyContextProvider(Component)) {\n      return processChildContext(fiber, Component, parentContext);\n    }\n  }\n\n  return parentContext;\n}\n\nfunction findHostInstance(component: Object): PublicInstance | null {\n  const fiber = getInstance(component);\n  if (fiber === undefined) {\n    if (typeof component.render === 'function') {\n      throw new Error('Unable to find node on an unmounted component.');\n    } else {\n      const keys = Object.keys(component).join(',');\n      throw new Error(\n        `Argument appears to not be a ReactComponent. Keys: ${keys}`,\n      );\n    }\n  }\n  const hostFiber = findCurrentHostFiber(fiber);\n  if (hostFiber === null) {\n    return null;\n  }\n  return getPublicInstance(hostFiber.stateNode);\n}\n\nfunction findHostInstanceWithWarning(\n  component: Object,\n  methodName: string,\n): PublicInstance | null {","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/facebook/react/blob/eafeac097ba51e1eab809c07102126bd5f8e5425/packages/react-reconciler/src/ReactFiberReconciler.js#L146-L182","documentation":"findHostInstance (the engine behind ReactDOM.findDOMNode) resolves a component instance to its DOM node via the internal fiber link on the instance. getInstance returned undefined while the object still has a render method, meaning it is a class instance whose fiber link is gone — a component that has already unmounted. findDOMNode is also deprecated, so this pattern should disappear entirely.","triggerScenarios":"ReactDOM.findDOMNode(instance) called after that component unmounted: timers (setTimeout/requestAnimationFrame) firing post-unmount, promise callbacks resolving late, event handlers or store subscribers holding stale child refs.","commonSituations":"Cleanup races in class components; findDOMNode(this.refs.child) after the child swapped out; instances captured in long-lived objects (stores, observers) and queried later.","solutions":["Replace findDOMNode with refs (createRef / callback refs) on the element you need — findDOMNode is deprecated and discouraged under StrictMode","Clear timers, subscriptions, and pending callbacks in componentWillUnmount so nothing runs after unmount","Null out stored refs when the component unmounts and check them before use","If a deferred callback must run, bail out early when the component (or its ref) is gone"],"exampleFix":"// before\ncomponentDidMount() {\n  this.timer = setTimeout(() => {\n    const node = findDOMNode(this.child); // child may have unmounted -> throws\n    node.focus();\n  }, 1000);\n}\n\n// after\nconstructor(props) {\n  super(props);\n  this.nodeRef = React.createRef();\n}\ncomponentDidMount() {\n  this.timer = setTimeout(() => {\n    if (this.nodeRef.current) this.nodeRef.current.focus();\n  }, 1000);\n}\ncomponentWillUnmount() {\n  clearTimeout(this.timer);\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// Pragmatic mounted-instance guard (fiber link exists = still mounted)\nfunction isMountedClassInstance(x: unknown): boolean {\n  return (\n    x != null &&\n    typeof x === 'object' &&\n    typeof (x as any).render === 'function' &&\n    (x as any)._reactInternals !== undefined\n  );\n}","tryCatchPattern":null,"preventionTips":["Replace findDOMNode with createRef/callback refs — it is deprecated","Clear timers, RAFs, subscriptions, and pending promises in componentWillUnmount","Null out refs on unmount and check them before use in deferred callbacks","Prefer rendering-safe data flow (state via props) over resolving DOM nodes from instances"],"tags":["react","finddomnode","unmounted","refs","deprecated-api","lifecycle"],"backgroundTag":"finddomnode-unmounted-component","analyzedSha":"eafeac097ba51e1eab809c07102126bd5f8e5425","analyzedAt":"2026-08-21T22:01:08.818Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}