import type { Component } from 'react' ; import type { Fiber } from 'react-reconciler' ; import { Int } from '../env/internals' ; import { invariant } from '../invariant' ; param fiber param next param stop returns export function getFiberFromPath ( fiber , next , stop ) { while ( fiber ) { if ( stop ( fiber ) ) { return fiber ; } fiber = next ( fiber ) ; } return null ; } param fiber returns export function getCurrentFiber ( fiber ) { if ( fiber . alternate === null ) { return fiber ; } let topFiber = fiber ; while ( topFiber . return !== null ) { topFiber = topFiber . return ; } invariant ( topFiber . stateNode !== null && 'current' in topFiber . stateNode , 'Unable to find node on an unmounted component.' ) ; const rootFiber = topFiber . stateNode ; const topCurrentFiber = rootFiber . current ; return topCurrentFiber === topFiber ? fiber : fiber . alternate ; } param element returns export function getFiberFromElementInstance < T extends Node > ( element ) { const internalKey = Object . keys ( element ) . find ( ( key ) => key . startsWith ( Int . nodePrefix ) ) ; invariant ( typeof internalKey === 'string' , `Cannot find the ${ Int . nodePrefix }. ` + `This is a problem with React-reparenting, please file an issue.` ) ; return element [ internalKey ] ; } param instance returns export function getFiberFromClassInstance ( instance ) { invariant ( Int . componentAttribute in instance , 'Cannot find the _reactInternalFiber. ' + 'This is a problem with React-reparenting, please file an issue.' ) ; return instance [ Int . componentAttribute ] ; }