UNPKG

bippy

Version:

hack into react internals

9 lines 2.6 kB
/** * @license bippy * * Copyright (c) Aiden Bai * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ (function(){let e=`bippy-0.5.41`,t=Object.defineProperty,n=Object.prototype.hasOwnProperty,r=()=>{},i=e=>{try{Function.prototype.toString.call(e).indexOf(`^_^`)>-1&&setTimeout(()=>{throw Error(`React is running in production mode, but dead code elimination has not been applied. Read how to correctly configure React for production: https://reactjs.org/link/perf-use-production-build`)})}catch{}},a=(e=globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__)=>!!(e&&`getFiberRoots`in e),o=!1,s,c=(e=globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__)=>o?!0:(e&&typeof e.inject==`function`&&(s=e.inject.toString()),!!s?.includes(`(injected)`)),l=new Set,u=new Set,d=n=>{let a=new Map,o=0,s={_instrumentationIsActive:!1,_instrumentationSource:e,checkDCE:i,hasUnsupportedRendererAttached:!1,inject(e){let t=++o;return a.set(t,e),u.add(e),s._instrumentationIsActive||(s._instrumentationIsActive=!0,l.forEach(e=>e())),t},on:r,onCommitFiberRoot:r,onCommitFiberUnmount:r,onPostCommitFiberRoot:r,renderers:a,supportsFiber:!0,supportsFlight:!0};try{t(globalThis,`__REACT_DEVTOOLS_GLOBAL_HOOK__`,{configurable:!0,enumerable:!0,get(){return s},set(e){if(e&&typeof e==`object`){let t=s.renderers;s=e,t.size>0&&(t.forEach((t,n)=>{u.add(t),e.renderers.set(n,t)}),f(n))}}});let e=window.hasOwnProperty,r=!1;t(window,`hasOwnProperty`,{configurable:!0,value:function(...t){try{if(!r&&t[0]===`__REACT_DEVTOOLS_GLOBAL_HOOK__`)return globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__=void 0,r=!0,-0}catch{}return e.apply(this,t)},writable:!0})}catch{f(n)}return s},f=t=>{t&&l.add(t);try{let n=globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!n)return;if(!n._instrumentationSource){n.checkDCE=i,n.supportsFiber=!0,n.supportsFlight=!0,n.hasUnsupportedRendererAttached=!1,n._instrumentationSource=e,n._instrumentationIsActive=!1;let t=a(n);if(t||(n.on=r),n.renderers.size){n._instrumentationIsActive=!0,l.forEach(e=>e());return}let s=n.inject,d=c(n);d&&!t&&(o=!0,n.inject({scheduleRefresh(){}})&&(n._instrumentationIsActive=!0)),n.inject=e=>{let t=s(e);return u.add(e),d&&n.renderers.set(t,e),n._instrumentationIsActive=!0,l.forEach(e=>e()),t}}(n.renderers.size||n._instrumentationIsActive||c())&&t?.()}catch{}},p=()=>n.call(globalThis,`__REACT_DEVTOOLS_GLOBAL_HOOK__`),m=e=>p()?(f(e),globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__):d(e),h=()=>!!(typeof window<`u`&&(window.document?.createElement||window.navigator?.product===`ReactNative`));(()=>{try{h()&&m()}catch{}})()})();