import type {Source} from 'shared/ReactElementType';
import type {
RefObject,
ReactContext,
MutableSourceSubscribeFn,
MutableSourceGetSnapshotFn,
MutableSourceVersion,
MutableSource,
StartTransitionOptions,
Wakeable,
Usable,
} from 'shared/ReactTypes';
import type {WorkTag} from './ReactWorkTags';
import type {TypeOfMode} from './ReactTypeOfMode';
import type {Flags} from './ReactFiberFlags';
import type {Lane, Lanes, LaneMap} from './ReactFiberLane';
import type {RootTag} from './ReactRootTags';
import type {
Container,
TimeoutHandle,
NoTimeout,
SuspenseInstance,
} from './ReactFiberHostConfig';
import type {Cache} from './ReactFiberCacheComponent';
import type {
TracingMarkerInstance,
Transition,
} from './ReactFiberTracingMarkerComponent';
import type {ConcurrentUpdate} from './ReactFiberConcurrentUpdates';
export type HookType =
| 'useState'
| 'useReducer'
| 'useContext'
| 'useRef'
| 'useEffect'
| 'useEffectEvent'
| 'useInsertionEffect'
| 'useLayoutEffect'
| 'useCallback'
| 'useMemo'
| 'useImperativeHandle'
| 'useDebugValue'
| 'useDeferredValue'
| 'useTransition'
| 'useMutableSource'
| 'useSyncExternalStore'
| 'useId'
| 'useCacheRefresh';
export type ContextDependency<T> = {
context: ReactContext<T>,
next: ContextDependency<mixed> | null,
memoizedValue: T,
...
};
export type Dependencies = {
lanes: Lanes,
firstContext: ContextDependency<mixed> | null,
...
};
export type MemoCache = {
data: Array<Array<any>>,
index: number,
};
export type Fiber = {
tag: WorkTag,
key: null | string,
elementType: any,
type: any,
stateNode: any,
return: Fiber | null,
child: Fiber | null,
sibling: Fiber | null,
index: number,
ref:
| null
| (((handle: mixed) => void) & {_stringRef: ?string, ...})
| RefObject,
refCleanup: null | (() => void),
pendingProps: any,
memoizedProps: any,
updateQueue: mixed,
memoizedState: any,
dependencies: Dependencies | null,
mode: TypeOfMode,
flags: Flags,
subtreeFlags: Flags,
deletions: Array<Fiber> | null,
nextEffect: Fiber | null,
firstEffect: Fiber | null,
lastEffect: Fiber | null,
lanes: Lanes,
childLanes: Lanes,
alternate: Fiber | null,
actualDuration?: number,
actualStartTime?: number,
selfBaseDuration?: number,
treeBaseDuration?: number,
_debugSource?: Source | null,
_debugOwner?: Fiber | null,
_debugIsCurrentlyTiming?: boolean,
_debugNeedsRemount?: boolean,
_debugHookTypes?: Array<HookType> | null,
};
type BaseFiberRootProperties = {
tag: RootTag,
containerInfo: Container,
pendingChildren: any,
current: Fiber,
pingCache: WeakMap<Wakeable, Set<mixed>> | Map<Wakeable, Set<mixed>> | null,
finishedWork: Fiber | null,
timeoutHandle: TimeoutHandle | NoTimeout,
cancelPendingCommit: null | (() => void),
context: Object | null,
pendingContext: Object | null,
mutableSourceEagerHydrationData?: Array<
MutableSource<any> | MutableSourceVersion,
> | null,
callbackNode: any,
callbackPriority: Lane,
eventTimes: LaneMap<number>,
expirationTimes: LaneMap<number>,
hiddenUpdates: LaneMap<Array<ConcurrentUpdate> | null>,
pendingLanes: Lanes,
suspendedLanes: Lanes,
pingedLanes: Lanes,
expiredLanes: Lanes,
mutableReadLanes: Lanes,
errorRecoveryDisabledLanes: Lanes,
finishedLanes: Lanes,
entangledLanes: Lanes,
entanglements: LaneMap<Lanes>,
pooledCache: Cache | null,
pooledCacheLanes: Lanes,
identifierPrefix: string,
onRecoverableError: (
error: mixed,
errorInfo: {digest?: ?string, componentStack?: ?string},
) => void,
};
type UpdaterTrackingOnlyFiberRootProperties = {
memoizedUpdaters: Set<Fiber>,
pendingUpdatersLaneMap: LaneMap<Set<Fiber>>,
};
export type SuspenseHydrationCallbacks = {
onHydrated?: (suspenseInstance: SuspenseInstance) => void,
onDeleted?: (suspenseInstance: SuspenseInstance) => void,
...
};
type SuspenseCallbackOnlyFiberRootProperties = {
hydrationCallbacks: null | SuspenseHydrationCallbacks,
};
export type TransitionTracingCallbacks = {
onTransitionStart?: (transitionName: string, startTime: number) => void,
onTransitionProgress?: (
transitionName: string,
startTime: number,
currentTime: number,
pending: Array<{name: null | string}>,
) => void,
onTransitionIncomplete?: (
transitionName: string,
startTime: number,
deletions: Array<{
type: string,
name?: string | null,
endTime: number,
}>,
) => void,
onTransitionComplete?: (
transitionName: string,
startTime: number,
endTime: number,
) => void,
onMarkerProgress?: (
transitionName: string,
marker: string,
startTime: number,
currentTime: number,
pending: Array<{name: null | string}>,
) => void,
onMarkerIncomplete?: (
transitionName: string,
marker: string,
startTime: number,
deletions: Array<{
type: string,
name?: string | null,
endTime: number,
}>,
) => void,
onMarkerComplete?: (
transitionName: string,
marker: string,
startTime: number,
endTime: number,
) => void,
};
type TransitionTracingOnlyFiberRootProperties = {
transitionCallbacks: null | TransitionTracingCallbacks,
transitionLanes: Array<Set<Transition> | null>,
incompleteTransitions: Map<Transition, TracingMarkerInstance>,
};
export type FiberRoot = {
...BaseFiberRootProperties,
...SuspenseCallbackOnlyFiberRootProperties,
...UpdaterTrackingOnlyFiberRootProperties,
...TransitionTracingOnlyFiberRootProperties,
...
};
type BasicStateAction<S> = (S => S) | S;
type Dispatch<A> = A => void;
export type Dispatcher = {
use?: <T>(Usable<T>) => T,
readContext<T>(context: ReactContext<T>): T,
useState<S>(initialState: (() => S) | S): [S, Dispatch<BasicStateAction<S>>],
useReducer<S, I, A>(
reducer: (S, A) => S,
initialArg: I,
init?: (I) => S,
): [S, Dispatch<A>],
useContext<T>(context: ReactContext<T>): T,
useRef<T>(initialValue: T): {current: T},
useEffect(
create: () => (() => void) | void,
deps: Array<mixed> | void | null,
): void,
useEffectEvent?: <Args, Return, F: (...Array<Args>) => Return>(
callback: F,
) => F,
useInsertionEffect(
create: () => (() => void) | void,
deps: Array<mixed> | void | null,
): void,
useLayoutEffect(
create: () => (() => void) | void,
deps: Array<mixed> | void | null,
): void,
useCallback<T>(callback: T, deps: Array<mixed> | void | null): T,
useMemo<T>(nextCreate: () => T, deps: Array<mixed> | void | null): T,
useImperativeHandle<T>(
ref: {current: T | null} | ((inst: T | null) => mixed) | null | void,
create: () => T,
deps: Array<mixed> | void | null,
): void,
useDebugValue<T>(value: T, formatterFn: ?(value: T) => mixed): void,
useDeferredValue<T>(value: T): T,
useTransition(): [
boolean,
(callback: () => void, options?: StartTransitionOptions) => void,
],
useMutableSource<TSource, Snapshot>(
source: MutableSource<TSource>,
getSnapshot: MutableSourceGetSnapshotFn<TSource, Snapshot>,
subscribe: MutableSourceSubscribeFn<TSource, Snapshot>,
): Snapshot,
useSyncExternalStore<T>(
subscribe: (() => void) => () => void,
getSnapshot: () => T,
getServerSnapshot?: () => T,
): T,
useId(): string,
useCacheRefresh?: () => <T>(?() => T, ?T) => void,
useMemoCache?: (size: number) => Array<any>,
};
export type CacheDispatcher = {
getCacheSignal: () => AbortSignal,
getCacheForType: <T>(resourceType: () => T) => T,
};