@@ -29,6 +29,7 @@ import {
29
29
ContextProvider ,
30
30
ForwardRef ,
31
31
} from 'react-reconciler/src/ReactWorkTags' ;
32
+ import { createUnsupportedFeatureError } from './ReactDebugCustomErrors' ;
32
33
33
34
type CurrentDispatcherRef = typeof ReactSharedInternals . ReactCurrentDispatcher ;
34
35
@@ -356,6 +357,19 @@ const Dispatcher: DispatcherType = {
356
357
useId ,
357
358
} ;
358
359
360
+ // create a proxy to throw a custom error
361
+ // in case future versions of React adds more hooks
362
+ const DispatcherProxyHandler = {
363
+ get ( target , prop , _receiver ) {
364
+ if ( target . hasOwnProperty ( prop ) ) {
365
+ return Reflect . get ( ...arguments ) ;
366
+ }
367
+ throw createUnsupportedFeatureError('Missing method in Dispatcher: ' + prop);
368
+ } ,
369
+ } ;
370
+
371
+ const DispatcherProxy = new Proxy ( Dispatcher , DispatcherProxyHandler ) ;
372
+
359
373
// Inspect
360
374
361
375
export type HookSource = {
@@ -664,7 +678,7 @@ export function inspectHooks<Props>(
664
678
665
679
const previousDispatcher = currentDispatcher . current ;
666
680
let readHookLog ;
667
- currentDispatcher . current = Dispatcher ;
681
+ currentDispatcher . current = DispatcherProxy ;
668
682
let ancestorStackError ;
669
683
try {
670
684
ancestorStackError = new Error ( ) ;
@@ -708,7 +722,7 @@ function inspectHooksOfForwardRef<Props, Ref>(
708
722
) : HooksTree {
709
723
const previousDispatcher = currentDispatcher . current ;
710
724
let readHookLog ;
711
- currentDispatcher . current = Dispatcher ;
725
+ currentDispatcher . current = DispatcherProxy ;
712
726
let ancestorStackError ;
713
727
try {
714
728
ancestorStackError = new Error ( ) ;
0 commit comments