declare const __REACT_DEVTOOLS_GLOBAL_HOOK__: Object | void;
export function injectInternals(internals: Object): boolean {
if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === 'undefined') {
// No DevTools
// 无开发者工具
return false;
}
const hook = __REACT_DEVTOOLS_GLOBAL_HOOK__;
if (hook.isDisabled) {
// This isn't a real property on the hook, but it can be set to opt out
// of DevTools integration and associated warnings and logs.
// 这不是 hook 上的真实属性,但可以设置以选择退出
// 开发者工具集成以及相关的警告和日志。
// https://github.com/facebook/react/issues/3877
return true;
}
if (!hook.supportsFlight) {
// DevTools exists, even though it doesn't support Flight.
// DevTools 存在,即使它不支持 Flight。
return true;
}
try {
hook.inject(internals);
} catch (err) {
// Catch all errors because it is unsafe to throw during initialization.
// 捕获所有错误,因为在初始化期间抛出异常是不安全的。
if (__DEV__) {
console.error('React instrumentation encountered an error: %o.', err);
}
}
if (hook.checkDCE) {
// This is the real DevTools.
// 这是真正的开发者工具。
return true;
} else {
// This is likely a hook installed by Fast Refresh runtime.
// 这可能是由 Fast Refresh 运行时安装的钩子。
return false;
}
}