/
react-dom_v18.x.x.js
291 lines (244 loc) · 8.23 KB
/
react-dom_v18.x.x.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
declare module 'react-dom_shared-types' {
/**
* Copied from react-reconciler
* https://github.com/facebook/react/blob/168da8d55782f3b34e2a6aa0c4dd0587696afdbd/packages/react-reconciler/src/ReactInternalTypes.js#L271
*/
declare 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,
newName?: string,
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,
newName?: string,
endTime: number,
|}>,
) => void,
onMarkerComplete?: (
transitionName: string,
marker: string,
startTime: number,
endTime: number,
) => void,
|};
declare type ReactEmpty = null | void | boolean;
declare type ReactNodeList = ReactEmpty | React$Node;
// Mutable source version can be anything (e.g. number, string, immutable data structure)
// so long as it changes every time any part of the source changes.
declare type MutableSourceVersion = $NonMaybeType<mixed>;
declare type MutableSourceGetVersionFn = (
source: $NonMaybeType<mixed>,
) => MutableSourceVersion;
declare type MutableSource<Source: $NonMaybeType<mixed>> = {|
_source: Source,
_getVersion: MutableSourceGetVersionFn,
// Tracks the version of this source at the time it was most recently read.
// Used to determine if a source is safe to read from before it has been subscribed to.
// Version number is only used during mount,
// since the mechanism for determining safety after subscription is expiration time.
//
// As a workaround to support multiple concurrent renderers,
// we categorize some renderers as primary and others as secondary.
// We only expect there to be two concurrent renderers at most:
// React Native (primary) and Fabric (secondary);
// React DOM (primary) and React ART (secondary).
// Secondary renderers store their context values on separate fields.
// We use the same approach for Context.
_workInProgressVersionPrimary: null | MutableSourceVersion,
_workInProgressVersionSecondary: null | MutableSourceVersion,
// DEV only
// Used to detect multiple renderers using the same mutable source.
_currentPrimaryRenderer?: any,
_currentSecondaryRenderer?: any,
// DEV only
// Used to detect side effects that update a mutable source during render.
// See https://github.com/facebook/react/issues/19948
_currentlyRenderingFiber?: any,
_initialVersionAsOfFirstRender?: MutableSourceVersion | null,
|};
}
declare module 'react-dom' {
declare var version: string;
declare function findDOMNode(
componentOrElement: Element | ?React$Component<any, any>
): null | Element | Text;
declare function render<ElementType: React$ElementType>(
element: React$Element<ElementType>,
container: Element,
callback?: () => void
): React$ElementRef<ElementType>;
declare function hydrate<ElementType: React$ElementType>(
element: React$Element<ElementType>,
container: Element,
callback?: () => void
): React$ElementRef<ElementType>;
declare function createPortal(
node: React$Node,
container: Element
): React$Portal;
declare function unmountComponentAtNode(container: any): boolean;
declare function flushSync(callback: () => mixed): void;
declare function unstable_batchedUpdates<A, B, C, D, E>(
callback: (a: A, b: B, c: C, d: D, e: E) => mixed,
a: A,
b: B,
c: C,
d: D,
e: E
): void;
declare function unstable_renderSubtreeIntoContainer<
ElementType: React$ElementType
>(
parentComponent: React$Component<any, any>,
nextElement: React$Element<ElementType>,
container: any,
callback?: () => void
): React$ElementRef<ElementType>;
}
declare module 'react-dom/client' {
import type {
TransitionTracingCallbacks,
ReactNodeList,
MutableSource,
} from 'react-dom_shared-types';
declare opaque type FiberRoot;
declare export type RootType = {
render(children: ReactNodeList): void,
unmount(): void,
_internalRoot: FiberRoot | null,
...
};
declare type CreateRootOptions = {
unstable_strictMode?: boolean,
unstable_concurrentUpdatesByDefault?: boolean,
identifierPrefix?: string,
onRecoverableError?: (error: mixed) => void,
transitionCallbacks?: TransitionTracingCallbacks,
...
};
declare export function createRoot(
container: Element | DocumentFragment,
options?: CreateRootOptions,
): RootType;
declare type HydrateRootOptions = {
// Hydration options
hydratedSources?: Array<MutableSource<any>>,
onHydrated?: (suspenseNode: Comment) => void,
onDeleted?: (suspenseNode: Comment) => void,
// Options for all roots
unstable_strictMode?: boolean,
unstable_concurrentUpdatesByDefault?: boolean,
identifierPrefix?: string,
onRecoverableError?: (error: mixed) => void,
...
};
declare export function hydrateRoot(
container: Document | Element,
initialChildren: ReactNodeList,
options?: HydrateRootOptions,
): RootType;
}
declare module 'react-dom/server' {
declare var version: string;
declare function renderToString(element: React$Node): string;
declare function renderToStaticMarkup(element: React$Node): string;
declare function renderToNodeStream(element: React$Node): stream$Readable;
declare function renderToStaticNodeStream(
element: React$Node
): stream$Readable;
}
declare module 'react-dom/test-utils' {
declare interface Thenable {
then(resolve: () => mixed, reject?: () => mixed): mixed,
}
declare var Simulate: {
[eventName: string]: (
element: Element,
eventData?: { [key: string]: mixed, ... }
) => void,
...
};
declare function renderIntoDocument(
instance: React$Element<any>
): React$Component<any, any>;
declare function mockComponent(
componentClass: React$ElementType,
mockTagName?: string
): { [key: string]: mixed, ... };
declare function isElement(element: React$Element<any>): boolean;
declare function isElementOfType(
element: React$Element<any>,
componentClass: React$ElementType
): boolean;
declare function isDOMComponent(instance: any): boolean;
declare function isCompositeComponent(
instance: React$Component<any, any>
): boolean;
declare function isCompositeComponentWithType(
instance: React$Component<any, any>,
componentClass: React$ElementType
): boolean;
declare function findAllInRenderedTree(
tree: React$Component<any, any>,
test: (child: React$Component<any, any>) => boolean
): Array<React$Component<any, any>>;
declare function scryRenderedDOMComponentsWithClass(
tree: React$Component<any, any>,
className: string
): Array<Element>;
declare function findRenderedDOMComponentWithClass(
tree: React$Component<any, any>,
className: string
): ?Element;
declare function scryRenderedDOMComponentsWithTag(
tree: React$Component<any, any>,
tagName: string
): Array<Element>;
declare function findRenderedDOMComponentWithTag(
tree: React$Component<any, any>,
tagName: string
): ?Element;
declare function scryRenderedComponentsWithType(
tree: React$Component<any, any>,
componentClass: React$ElementType
): Array<React$Component<any, any>>;
declare function findRenderedComponentWithType(
tree: React$Component<any, any>,
componentClass: React$ElementType
): ?React$Component<any, any>;
declare function act(callback: () => void | Thenable): Thenable;
}