File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed
packages/react-debug-tools/src Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -356,6 +356,23 @@ const Dispatcher: DispatcherType = {
356356 useId ,
357357} ;
358358
359+ // create a proxy to throw a custom error
360+ // in case future versions of React adds more hooks
361+ const DispatcherProxyHandler = {
362+ get ( target , prop ) {
363+ if ( target . hasOwnProperty ( prop ) ) {
364+ return target [ prop ] ;
365+ }
366+ const error = new Error('Missing method in Dispatcher: ' + prop);
367+ // Note: This error name needs to stay in sync with react-devtools-shared
368+ // TODO: refactor this if we ever combine the devtools and debug tools packages
369+ error.name = 'UnsupportedFeatureError';
370+ throw error;
371+ } ,
372+ } ;
373+
374+ const DispatcherProxy = new Proxy ( Dispatcher , DispatcherProxyHandler ) ;
375+
359376// Inspect
360377
361378export type HookSource = {
@@ -664,7 +681,7 @@ export function inspectHooks<Props>(
664681
665682 const previousDispatcher = currentDispatcher . current ;
666683 let readHookLog ;
667- currentDispatcher . current = Dispatcher ;
684+ currentDispatcher . current = DispatcherProxy ;
668685 let ancestorStackError ;
669686 try {
670687 ancestorStackError = new Error ( ) ;
@@ -708,7 +725,7 @@ function inspectHooksOfForwardRef<Props, Ref>(
708725) : HooksTree {
709726 const previousDispatcher = currentDispatcher . current ;
710727 let readHookLog ;
711- currentDispatcher . current = Dispatcher ;
728+ currentDispatcher . current = DispatcherProxy ;
712729 let ancestorStackError ;
713730 try {
714731 ancestorStackError = new Error ( ) ;
You can’t perform that action at this time.
0 commit comments