GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [ReactDebugTools] add custom error type for future new hooks (#24168) · react/react@0415b18

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/react-debug-tools/src
    • ReactDebugHooks.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: packages/react-debug-tools/src/ReactDebugHooks.js
+19-2Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff 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

361378
export 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();

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.