Skip to content

Commit d6e3d16

Browse files
committed
Add useId to dispatcher
1 parent 9c8161b commit d6e3d16

File tree

16 files changed

+132
-0
lines changed

16 files changed

+132
-0
lines changed

packages/react-debug-tools/src/ReactDebugHooks.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,10 @@ function useOpaqueIdentifier(): OpaqueIDType | void {
341341
return value;
342342
}
343343

344+
function useId(): string {
345+
throw new Error('Not implemented.');
346+
}
347+
344348
const Dispatcher: DispatcherType = {
345349
getCacheForType,
346350
readContext,
@@ -361,6 +365,7 @@ const Dispatcher: DispatcherType = {
361365
useSyncExternalStore,
362366
useDeferredValue,
363367
useOpaqueIdentifier,
368+
useId,
364369
};
365370

366371
// Inspect

packages/react-dom/src/server/ReactPartialRendererHooks.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,10 @@ function useOpaqueIdentifier(): OpaqueIDType {
519519
);
520520
}
521521

522+
function useId(): OpaqueIDType {
523+
throw new Error('Not implemented.');
524+
}
525+
522526
function useCacheRefresh(): <T>(?() => T, ?T) => void {
523527
throw new Error('Not implemented.');
524528
}
@@ -549,6 +553,7 @@ export const Dispatcher: DispatcherType = {
549553
useDeferredValue,
550554
useTransition,
551555
useOpaqueIdentifier,
556+
useId,
552557
// Subscriptions are not setup in a server environment.
553558
useMutableSource,
554559
useSyncExternalStore,

packages/react-reconciler/src/ReactFiberHooks.new.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2096,6 +2096,14 @@ function rerenderOpaqueIdentifier(): OpaqueIDType | void {
20962096
return id;
20972097
}
20982098

2099+
function mountId(): string {
2100+
throw new Error('Not implemented.');
2101+
}
2102+
2103+
function updateId(): string {
2104+
throw new Error('Not implemented.');
2105+
}
2106+
20992107
function mountRefresh() {
21002108
const hook = mountWorkInProgressHook();
21012109
const refresh = (hook.memoizedState = refreshCache.bind(
@@ -2412,6 +2420,7 @@ export const ContextOnlyDispatcher: Dispatcher = {
24122420
useMutableSource: throwInvalidHookError,
24132421
useSyncExternalStore: throwInvalidHookError,
24142422
useOpaqueIdentifier: throwInvalidHookError,
2423+
useId: throwInvalidHookError,
24152424

24162425
unstable_isNewReconciler: enableNewReconciler,
24172426
};
@@ -2440,6 +2449,7 @@ const HooksDispatcherOnMount: Dispatcher = {
24402449
useMutableSource: mountMutableSource,
24412450
useSyncExternalStore: mountSyncExternalStore,
24422451
useOpaqueIdentifier: mountOpaqueIdentifier,
2452+
useId: mountId,
24432453

24442454
unstable_isNewReconciler: enableNewReconciler,
24452455
};
@@ -2468,6 +2478,7 @@ const HooksDispatcherOnUpdate: Dispatcher = {
24682478
useMutableSource: updateMutableSource,
24692479
useSyncExternalStore: updateSyncExternalStore,
24702480
useOpaqueIdentifier: updateOpaqueIdentifier,
2481+
useId: updateId,
24712482

24722483
unstable_isNewReconciler: enableNewReconciler,
24732484
};
@@ -2496,6 +2507,7 @@ const HooksDispatcherOnRerender: Dispatcher = {
24962507
useMutableSource: updateMutableSource,
24972508
useSyncExternalStore: mountSyncExternalStore,
24982509
useOpaqueIdentifier: rerenderOpaqueIdentifier,
2510+
useId: updateId,
24992511

25002512
unstable_isNewReconciler: enableNewReconciler,
25012513
};
@@ -2667,6 +2679,11 @@ if (__DEV__) {
26672679
mountHookTypesDev();
26682680
return mountOpaqueIdentifier();
26692681
},
2682+
useId(): string {
2683+
currentHookNameInDev = 'useId';
2684+
mountHookTypesDev();
2685+
return mountId();
2686+
},
26702687

26712688
unstable_isNewReconciler: enableNewReconciler,
26722689
};
@@ -2809,6 +2826,11 @@ if (__DEV__) {
28092826
updateHookTypesDev();
28102827
return mountOpaqueIdentifier();
28112828
},
2829+
useId(): string {
2830+
currentHookNameInDev = 'useId';
2831+
updateHookTypesDev();
2832+
return mountId();
2833+
},
28122834

28132835
unstable_isNewReconciler: enableNewReconciler,
28142836
};
@@ -2951,6 +2973,11 @@ if (__DEV__) {
29512973
updateHookTypesDev();
29522974
return updateOpaqueIdentifier();
29532975
},
2976+
useId(): string {
2977+
currentHookNameInDev = 'useId';
2978+
updateHookTypesDev();
2979+
return updateId();
2980+
},
29542981

29552982
unstable_isNewReconciler: enableNewReconciler,
29562983
};
@@ -3094,6 +3121,11 @@ if (__DEV__) {
30943121
updateHookTypesDev();
30953122
return rerenderOpaqueIdentifier();
30963123
},
3124+
useId(): string {
3125+
currentHookNameInDev = 'useId';
3126+
updateHookTypesDev();
3127+
return updateId();
3128+
},
30973129

30983130
unstable_isNewReconciler: enableNewReconciler,
30993131
};
@@ -3253,6 +3285,12 @@ if (__DEV__) {
32533285
mountHookTypesDev();
32543286
return mountOpaqueIdentifier();
32553287
},
3288+
useId(): string {
3289+
currentHookNameInDev = 'useId';
3290+
warnInvalidHookAccess();
3291+
mountHookTypesDev();
3292+
return mountId();
3293+
},
32563294

32573295
unstable_isNewReconciler: enableNewReconciler,
32583296
};
@@ -3412,6 +3450,12 @@ if (__DEV__) {
34123450
updateHookTypesDev();
34133451
return updateOpaqueIdentifier();
34143452
},
3453+
useId(): string {
3454+
currentHookNameInDev = 'useId';
3455+
warnInvalidHookAccess();
3456+
updateHookTypesDev();
3457+
return updateId();
3458+
},
34153459

34163460
unstable_isNewReconciler: enableNewReconciler,
34173461
};
@@ -3572,6 +3616,12 @@ if (__DEV__) {
35723616
updateHookTypesDev();
35733617
return rerenderOpaqueIdentifier();
35743618
},
3619+
useId(): string {
3620+
currentHookNameInDev = 'useId';
3621+
warnInvalidHookAccess();
3622+
updateHookTypesDev();
3623+
return updateId();
3624+
},
35753625

35763626
unstable_isNewReconciler: enableNewReconciler,
35773627
};

packages/react-reconciler/src/ReactFiberHooks.old.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2096,6 +2096,14 @@ function rerenderOpaqueIdentifier(): OpaqueIDType | void {
20962096
return id;
20972097
}
20982098

2099+
function mountId(): string {
2100+
throw new Error('Not implemented.');
2101+
}
2102+
2103+
function updateId(): string {
2104+
throw new Error('Not implemented.');
2105+
}
2106+
20992107
function mountRefresh() {
21002108
const hook = mountWorkInProgressHook();
21012109
const refresh = (hook.memoizedState = refreshCache.bind(
@@ -2412,6 +2420,7 @@ export const ContextOnlyDispatcher: Dispatcher = {
24122420
useMutableSource: throwInvalidHookError,
24132421
useSyncExternalStore: throwInvalidHookError,
24142422
useOpaqueIdentifier: throwInvalidHookError,
2423+
useId: throwInvalidHookError,
24152424

24162425
unstable_isNewReconciler: enableNewReconciler,
24172426
};
@@ -2440,6 +2449,7 @@ const HooksDispatcherOnMount: Dispatcher = {
24402449
useMutableSource: mountMutableSource,
24412450
useSyncExternalStore: mountSyncExternalStore,
24422451
useOpaqueIdentifier: mountOpaqueIdentifier,
2452+
useId: mountId,
24432453

24442454
unstable_isNewReconciler: enableNewReconciler,
24452455
};
@@ -2468,6 +2478,7 @@ const HooksDispatcherOnUpdate: Dispatcher = {
24682478
useMutableSource: updateMutableSource,
24692479
useSyncExternalStore: updateSyncExternalStore,
24702480
useOpaqueIdentifier: updateOpaqueIdentifier,
2481+
useId: updateId,
24712482

24722483
unstable_isNewReconciler: enableNewReconciler,
24732484
};
@@ -2496,6 +2507,7 @@ const HooksDispatcherOnRerender: Dispatcher = {
24962507
useMutableSource: updateMutableSource,
24972508
useSyncExternalStore: mountSyncExternalStore,
24982509
useOpaqueIdentifier: rerenderOpaqueIdentifier,
2510+
useId: updateId,
24992511

25002512
unstable_isNewReconciler: enableNewReconciler,
25012513
};
@@ -2667,6 +2679,11 @@ if (__DEV__) {
26672679
mountHookTypesDev();
26682680
return mountOpaqueIdentifier();
26692681
},
2682+
useId(): string {
2683+
currentHookNameInDev = 'useId';
2684+
mountHookTypesDev();
2685+
return mountId();
2686+
},
26702687

26712688
unstable_isNewReconciler: enableNewReconciler,
26722689
};
@@ -2809,6 +2826,11 @@ if (__DEV__) {
28092826
updateHookTypesDev();
28102827
return mountOpaqueIdentifier();
28112828
},
2829+
useId(): string {
2830+
currentHookNameInDev = 'useId';
2831+
updateHookTypesDev();
2832+
return mountId();
2833+
},
28122834

28132835
unstable_isNewReconciler: enableNewReconciler,
28142836
};
@@ -2951,6 +2973,11 @@ if (__DEV__) {
29512973
updateHookTypesDev();
29522974
return updateOpaqueIdentifier();
29532975
},
2976+
useId(): string {
2977+
currentHookNameInDev = 'useId';
2978+
updateHookTypesDev();
2979+
return updateId();
2980+
},
29542981

29552982
unstable_isNewReconciler: enableNewReconciler,
29562983
};
@@ -3094,6 +3121,11 @@ if (__DEV__) {
30943121
updateHookTypesDev();
30953122
return rerenderOpaqueIdentifier();
30963123
},
3124+
useId(): string {
3125+
currentHookNameInDev = 'useId';
3126+
updateHookTypesDev();
3127+
return updateId();
3128+
},
30973129

30983130
unstable_isNewReconciler: enableNewReconciler,
30993131
};
@@ -3253,6 +3285,12 @@ if (__DEV__) {
32533285
mountHookTypesDev();
32543286
return mountOpaqueIdentifier();
32553287
},
3288+
useId(): string {
3289+
currentHookNameInDev = 'useId';
3290+
warnInvalidHookAccess();
3291+
mountHookTypesDev();
3292+
return mountId();
3293+
},
32563294

32573295
unstable_isNewReconciler: enableNewReconciler,
32583296
};
@@ -3412,6 +3450,12 @@ if (__DEV__) {
34123450
updateHookTypesDev();
34133451
return updateOpaqueIdentifier();
34143452
},
3453+
useId(): string {
3454+
currentHookNameInDev = 'useId';
3455+
warnInvalidHookAccess();
3456+
updateHookTypesDev();
3457+
return updateId();
3458+
},
34153459

34163460
unstable_isNewReconciler: enableNewReconciler,
34173461
};
@@ -3572,6 +3616,12 @@ if (__DEV__) {
35723616
updateHookTypesDev();
35733617
return rerenderOpaqueIdentifier();
35743618
},
3619+
useId(): string {
3620+
currentHookNameInDev = 'useId';
3621+
warnInvalidHookAccess();
3622+
updateHookTypesDev();
3623+
return updateId();
3624+
},
35753625

35763626
unstable_isNewReconciler: enableNewReconciler,
35773627
};

packages/react-reconciler/src/ReactInternalTypes.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export type HookType =
4444
| 'useMutableSource'
4545
| 'useSyncExternalStore'
4646
| 'useOpaqueIdentifier'
47+
| 'useId'
4748
| 'useCacheRefresh';
4849

4950
export type ContextDependency<T> = {
@@ -317,6 +318,7 @@ export type Dispatcher = {|
317318
getServerSnapshot?: () => T,
318319
): T,
319320
useOpaqueIdentifier(): any,
321+
useId(): string,
320322
useCacheRefresh?: () => <T>(?() => T, ?T) => void,
321323

322324
unstable_isNewReconciler?: boolean,

packages/react-server/src/ReactFizzHooks.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,10 @@ function useOpaqueIdentifier(): OpaqueIDType {
495495
return makeServerID(currentResponseState);
496496
}
497497

498+
function useId(): string {
499+
throw new Error('Not implemented.');
500+
}
501+
498502
function unsupportedRefresh() {
499503
throw new Error('Cache cannot be refreshed during server rendering.');
500504
}
@@ -524,6 +528,7 @@ export const Dispatcher: DispatcherType = {
524528
useDeferredValue,
525529
useTransition,
526530
useOpaqueIdentifier,
531+
useId,
527532
// Subscriptions are not setup in a server environment.
528533
useMutableSource,
529534
useSyncExternalStore,

packages/react-server/src/ReactFlightServer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,7 @@ const Dispatcher: DispatcherType = {
846846
useImperativeHandle: (unsupportedHook: any),
847847
useEffect: (unsupportedHook: any),
848848
useOpaqueIdentifier: (unsupportedHook: any),
849+
useId: (unsupportedHook: any),
849850
useMutableSource: (unsupportedHook: any),
850851
useSyncExternalStore: (unsupportedHook: any),
851852
useCacheRefresh(): <T>(?() => T, ?T) => void {

packages/react-suspense-test-utils/src/ReactSuspenseTestUtils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export function waitForSuspense<T>(fn: () => T): Promise<T> {
4343
useDeferredValue: unsupported,
4444
useTransition: unsupported,
4545
useOpaqueIdentifier: unsupported,
46+
useId: unsupported,
4647
useMutableSource: unsupported,
4748
useSyncExternalStore: unsupported,
4849
useCacheRefresh: unsupported,

packages/react/index.classic.fb.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export {
4141
unstable_getCacheForType,
4242
unstable_useCacheRefresh,
4343
unstable_useOpaqueIdentifier,
44+
unstable_useId,
4445
useCallback,
4546
useContext,
4647
useDebugValue,

packages/react/index.experimental.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export {
3737
unstable_getCacheForType,
3838
unstable_useCacheRefresh,
3939
unstable_useOpaqueIdentifier,
40+
unstable_useId,
4041
useCallback,
4142
useContext,
4243
useDebugValue,

0 commit comments

Comments
 (0)