Skip to content

Commit d633bb1

Browse files
authored
🤖 Merge PR DefinitelyTyped#72561 Add React 19 support by @zhanghaocong
1 parent 22bcea9 commit d633bb1

File tree

4 files changed

+148
-86
lines changed

4 files changed

+148
-86
lines changed

types/react-reconciler/index.d.ts

Lines changed: 71 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ declare function ReactReconciler<
99
TextInstance,
1010
SuspenseInstance,
1111
HydratableInstance,
12+
FormInstance,
1213
PublicInstance,
1314
HostContext,
14-
UpdatePayload,
1515
ChildSet,
1616
TimeoutHandle,
1717
NoTimeout,
18+
TransitionStatus,
1819
>(
1920
/* eslint-enable @definitelytyped/no-unnecessary-generics */
2021
config: ReactReconciler.HostConfig<
@@ -25,14 +26,15 @@ declare function ReactReconciler<
2526
TextInstance,
2627
SuspenseInstance,
2728
HydratableInstance,
29+
FormInstance,
2830
PublicInstance,
2931
HostContext,
30-
UpdatePayload,
3132
ChildSet,
3233
TimeoutHandle,
33-
NoTimeout
34+
NoTimeout,
35+
TransitionStatus
3436
>,
35-
): ReactReconciler.Reconciler<Container, Instance, TextInstance, SuspenseInstance, PublicInstance>;
37+
): ReactReconciler.Reconciler<Container, Instance, TextInstance, SuspenseInstance, FormInstance, PublicInstance>;
3638

3739
declare namespace ReactReconciler {
3840
interface HostConfig<
@@ -43,12 +45,13 @@ declare namespace ReactReconciler {
4345
TextInstance,
4446
SuspenseInstance,
4547
HydratableInstance,
48+
FormInstance,
4649
PublicInstance,
4750
HostContext,
48-
UpdatePayload,
4951
ChildSet,
5052
TimeoutHandle,
5153
NoTimeout,
54+
TransitionStatus,
5255
> {
5356
// -------------------
5457
// Modes
@@ -148,22 +151,6 @@ declare namespace ReactReconciler {
148151
hostContext: HostContext,
149152
): boolean;
150153

151-
/**
152-
* React calls this method so that you can compare the previous and the next props, and decide whether you need to update the underlying instance or not. If you don't need to update it, return `null`. If you need to update it, you can return an arbitrary object representing the changes that need to happen. Then in `commitUpdate` you would need to apply those changes to the instance.
153-
*
154-
* This method happens **in the render phase**. It should only *calculate* the update — but not apply it! For example, the DOM renderer returns an array that looks like `[prop1, value1, prop2, value2, ...]` for all props that have actually changed. And only in `commitUpdate` it applies those changes. You should calculate as much as you can in `prepareUpdate` so that `commitUpdate` can be very fast and straightforward.
155-
*
156-
* See the meaning of `rootContainer` and `hostContext` in the `createInstance` documentation.
157-
*/
158-
prepareUpdate(
159-
instance: Instance,
160-
type: Type,
161-
oldProps: Props,
162-
newProps: Props,
163-
rootContainer: Container,
164-
hostContext: HostContext,
165-
): UpdatePayload | null;
166-
167154
/**
168155
* Some target platforms support setting an instance's text content without manually creating a text node. For example, in the DOM, you can set `node.textContent` instead of creating a text node and appending it.
169156
*
@@ -237,7 +224,7 @@ declare namespace ReactReconciler {
237224
noTimeout: NoTimeout;
238225

239226
/**
240-
* Set this to `true` to indicate that your renderer supports `scheduleMicrotask`. We use microtasks as part of our discrete event implementation in React DOM. If you're not sure if your renderer should support this, you probably should. The option to not implement `scheduleMicrotask` exists so that platforms with more control over user events, like React Native, can choose to use a different mechanism.
227+
* Set this to true to indicate that your renderer supports `scheduleMicrotask`. We use microtasks as part of our discrete event implementation in React DOM. If you're not sure if your renderer should support this, you probably should. The option to not implement `scheduleMicrotask` exists so that platforms with more control over user events, like React Native, can choose to use a different mechanism.
241228
*/
242229
supportsMicrotasks?: boolean;
243230

@@ -256,39 +243,6 @@ declare namespace ReactReconciler {
256243
*/
257244
warnsIfNotActing?: boolean;
258245

259-
/**
260-
* To implement this method, you'll need some constants available on the special `react-reconciler/constants` entry point:
261-
*
262-
* ```
263-
* import {
264-
* DiscreteEventPriority,
265-
* ContinuousEventPriority,
266-
* DefaultEventPriority,
267-
* } from 'react-reconciler/constants';
268-
*
269-
* const HostConfig = {
270-
* // ...
271-
* getCurrentEventPriority() {
272-
* return DefaultEventPriority;
273-
* },
274-
* // ...
275-
* }
276-
*
277-
* const MyRenderer = Reconciler(HostConfig);
278-
* ```
279-
*
280-
* The constant you return depends on which event, if any, is being handled right now. (In the browser, you can check this using `window.event && window.event.type`).
281-
*
282-
* - **Discrete events**: If the active event is directly caused by the user (such as mouse and keyboard events) and each event in a sequence is intentional (e.g. click), return DiscreteEventPriority. This tells React that they should interrupt any background work and cannot be batched across time.
283-
*
284-
* - **Continuous events**: If the active event is directly caused by the user but the user can't distinguish between individual events in a sequence (e.g. mouseover), return ContinuousEventPriority. This tells React they should interrupt any background work but can be batched across time.
285-
*
286-
* - **Other events / No active event**: In all other cases, return DefaultEventPriority. This tells React that this event is considered background work, and interactive events will be prioritized over it.
287-
*
288-
* You can consult the `getCurrentEventPriority()` implementation in `ReactDOMHostConfig.js` for a reference implementation.
289-
*/
290-
getCurrentEventPriority(): Lane;
291-
292246
getInstanceFromNode(node: any): Fiber | null | undefined;
293247

294248
beforeActiveInstanceBlur(): void;
@@ -379,13 +333,12 @@ declare namespace ReactReconciler {
379333
commitMount?(instance: Instance, type: Type, props: Props, internalInstanceHandle: OpaqueHandle): void;
380334

381335
/**
382-
* This method should mutate the `instance` according to the set of changes in `updatePayload`. Here, `updatePayload` is the object that you've returned from `prepareUpdate` and has an arbitrary structure that makes sense for your renderer. For example, the DOM renderer returns an update payload like `[prop1, value1, prop2, value2, ...]` from `prepareUpdate`, and that structure gets passed into `commitUpdate`. Ideally, all the diffing and calculation should happen inside `prepareUpdate` so that `commitUpdate` can be fast and straightforward.
336+
* This method should mutate the instance to match nextProps.
383337
*
384-
* The `internalHandle` data structure is meant to be opaque. If you bend the rules and rely on its internal fields, be aware that it may change significantly between versions. You're taking on additional maintenance risk by reading from it, and giving up all guarantees if you write something to it.
338+
* The internalHandle data structure is meant to be opaque. If you bend the rules and rely on its internal fields, be aware that it may change significantly between versions. You're taking on additional maintenance risk by reading from it, and giving up all guarantees if you write something to it.
385339
*/
386340
commitUpdate?(
387341
instance: Instance,
388-
updatePayload: UpdatePayload,
389342
type: Type,
390343
prevProps: Props,
391344
nextProps: Props,
@@ -424,7 +377,6 @@ declare namespace ReactReconciler {
424377
// -------------------
425378
cloneInstance?(
426379
instance: Instance,
427-
updatePayload: UpdatePayload,
428380
type: Type,
429381
oldProps: Props,
430382
newProps: Props,
@@ -540,6 +492,63 @@ declare namespace ReactReconciler {
540492
didNotFindHydratableSuspenseInstance?(parentType: Type, parentProps: Props, parentInstance: Instance): void;
541493

542494
errorHydratingContainer?(parentContainer: Container): void;
495+
496+
// Undocumented
497+
// https://github.com/facebook/react/pull/26722
498+
NotPendingTransition: TransitionStatus | null;
499+
HostTransitionContext: ReactContext<TransitionStatus>;
500+
501+
// https://github.com/facebook/react/pull/28751
502+
setCurrentUpdatePriority(newPriority: EventPriority): void;
503+
getCurrentUpdatePriority(): EventPriority;
504+
resolveUpdatePriority(): EventPriority;
505+
506+
// https://github.com/facebook/react/pull/28804
507+
resetFormInstance(form: FormInstance): void;
508+
509+
// https://github.com/facebook/react/pull/25105
510+
requestPostPaintCallback(callback: (time: number) => void): void;
511+
512+
// https://github.com/facebook/react/pull/26025
513+
shouldAttemptEagerTransition(): boolean;
514+
515+
// https://github.com/facebook/react/pull/31528
516+
trackSchedulerEvent(): void;
517+
518+
// https://github.com/facebook/react/pull/31008
519+
resolveEventType(): null | string;
520+
resolveEventTimeStamp(): number;
521+
522+
/**
523+
* This method is called during render to determine if the Host Component type and props require some kind of loading process to complete before committing an update.
524+
*/
525+
maySuspendCommit(type: Type, props: Props): boolean;
526+
527+
/**
528+
* This method may be called during render if the Host Component type and props might suspend a commit. It can be used to initiate any work that might shorten the duration of a suspended commit.
529+
*/
530+
preloadInstance(type: Type, props: Props): boolean;
531+
532+
/**
533+
* This method is called just before the commit phase. Use it to set up any necessary state while any Host Components that might suspend this commit are evaluated to determine if the commit must be suspended.
534+
*/
535+
startSuspendingCommit(): void;
536+
537+
/**
538+
* This method is called after `startSuspendingCommit` for each Host Component that indicated it might suspend a commit.
539+
*/
540+
suspendInstance(type: Type, props: Props): void;
541+
542+
/**
543+
* This method is called after all `suspendInstance` calls are complete.
544+
*
545+
* Return `null` if the commit can happen immediately.
546+
*
547+
* Return `(initiateCommit: Function) => Function` if the commit must be suspended. The argument to this callback will initiate the commit when called. The return value is a cancellation function that the Reconciler can use to abort the commit.
548+
*/
549+
waitForCommitToBeReady():
550+
| ((initiateCommit: (...args: unknown[]) => unknown) => (...args: unknown[]) => unknown)
551+
| null;
543552
}
544553

545554
interface Thenable<T> {
@@ -608,6 +617,8 @@ declare namespace ReactReconciler {
608617

609618
type TypeOfMode = number;
610619

620+
type EventPriority = number;
621+
611622
interface ReactProvider<T> {
612623
$$typeof: symbol | number;
613624
type: ReactProviderType<T>;
@@ -639,7 +650,6 @@ declare namespace ReactReconciler {
639650
$$typeof: symbol | number;
640651
Consumer: ReactContext<T>;
641652
Provider: ReactProviderType<T>;
642-
_calculateChangedBits: ((a: T, b: T) => number) | null;
643653
_currentValue: T;
644654
_currentValue2: T;
645655
_threadCount: number;
@@ -916,7 +926,7 @@ declare namespace ReactReconciler {
916926

917927
type IntersectionObserverOptions = any;
918928

919-
interface Reconciler<Container, Instance, TextInstance, SuspenseInstance, PublicInstance> {
929+
interface Reconciler<Container, Instance, TextInstance, SuspenseInstance, FormInstance, PublicInstance> {
920930
createContainer(
921931
containerInfo: Container,
922932
tag: RootTag,

types/react-reconciler/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "@types/react-reconciler",
4-
"version": "0.31.9999",
4+
"version": "0.32.9999",
55
"projects": [
66
"https://reactjs.org/"
77
],

types/react-reconciler/test/ReactTestHostConfig.ts

Lines changed: 72 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
import ReactReconcilerConstants = require("react-reconciler/constants");
11+
import { ReactContext } from "react-reconciler";
1112

1213
export const REACT_OPAQUE_ID_TYPE: number | symbol = 0xeae0;
1314

@@ -41,16 +42,15 @@ export interface TextInstance {
4142
tag: "TEXT";
4243
}
4344
export type HydratableInstance = Instance | TextInstance;
45+
export type FormInstance = Instance;
4446
export type PublicInstance = (Instance | TextInstance) & { kind: "PublicInstance" };
4547
export interface HostContext {
4648
[key: string]: any;
4749
}
48-
export interface UpdatePayload {
49-
[key: string]: any;
50-
}
5150
export type ChildSet = undefined; // Unused
5251
export type TimeoutHandle = TimeoutID;
5352
export type NoTimeout = -1;
53+
export type TransitionStatus = any;
5454
export type EventResponder = any;
5555
export type OpaqueIDType =
5656
| string
@@ -187,19 +187,6 @@ export function finalizeInitialChildren(
187187
return false;
188188
}
189189

190-
export function prepareUpdate(
191-
testElement: Instance,
192-
type: string,
193-
oldProps: Props,
194-
newProps: Props,
195-
rootContainerInstance: Container,
196-
hostContext: {
197-
[key: string]: any;
198-
},
199-
): null | {} {
200-
return UPDATE_SIGNAL;
201-
}
202-
203190
export function shouldSetTextContent(type: string, props: Props): boolean {
204191
return false;
205192
}
@@ -221,10 +208,6 @@ export function createTextInstance(
221208
};
222209
}
223210

224-
export function getCurrentEventPriority() {
225-
return ReactReconcilerConstants.DefaultEventPriority;
226-
}
227-
228211
export const isPrimaryRenderer = false;
229212
export const warnsIfNotActing = true;
230213

@@ -241,7 +224,6 @@ export const supportsMutation = true;
241224

242225
export function commitUpdate(
243226
instance: Instance,
244-
updatePayload: {},
245227
type: string,
246228
oldProps: Props,
247229
newProps: Props,
@@ -334,3 +316,72 @@ export function detachDeletedInstance(node: Instance): void {
334316
export function logRecoverableError(error: any): void {
335317
// noop
336318
}
319+
320+
export const NotPendingTransition = null;
321+
322+
export function shouldAttemptEagerTransition() {
323+
return false;
324+
}
325+
326+
export function startSuspendingCommit() {
327+
// noop
328+
}
329+
330+
export function suspendInstance() {
331+
// noop
332+
}
333+
334+
export function trackSchedulerEvent() {
335+
// noop
336+
}
337+
338+
export function waitForCommitToBeReady() {
339+
return null;
340+
}
341+
342+
export function getCurrentUpdatePriority() {
343+
return ReactReconcilerConstants.DefaultEventPriority;
344+
}
345+
346+
export function resolveUpdatePriority() {
347+
return ReactReconcilerConstants.DefaultEventPriority;
348+
}
349+
350+
export function setCurrentUpdatePriority(newPriority: number) {
351+
// noop
352+
}
353+
354+
export function requestPostPaintCallback() {
355+
// noop
356+
}
357+
358+
export function resetFormInstance() {
359+
// noop
360+
}
361+
362+
export function resolveEventTimeStamp() {
363+
return -1.1;
364+
}
365+
366+
export function resolveEventType() {
367+
return null;
368+
}
369+
370+
export function maySuspendCommit() {
371+
return false;
372+
}
373+
374+
export function preloadInstance() {
375+
return true;
376+
}
377+
378+
const REACT_CONTEXT_TYPE = Symbol.for("react.context");
379+
380+
export const HostTransitionContext: ReactContext<TransitionStatus> = {
381+
$$typeof: REACT_CONTEXT_TYPE,
382+
Provider: null as any,
383+
Consumer: null as any,
384+
_currentValue: NotPendingTransition,
385+
_currentValue2: NotPendingTransition,
386+
_threadCount: 0,
387+
};

0 commit comments

Comments
 (0)