UNPKG

bippy

Version:

hack into react internals

9 lines 2.51 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=`0.5.6`,t=`bippy-${e}`,n=Object.defineProperty,r=Object.prototype.hasOwnProperty,i=()=>{},a=e=>{try{let t=Function.prototype.toString.call(e);t.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{}},o=(e=h())=>`getFiberRoots`in e,s=!1,c,l=(e=h())=>s?!0:(typeof e.inject==`function`&&(c=e.inject.toString()),!!c?.includes(`(injected)`)),u=new Set,d=new Set,f=e=>{let r=new Map,o=0,s={_instrumentationIsActive:!1,_instrumentationSource:t,checkDCE:a,hasUnsupportedRendererAttached:!1,inject(e){let t=++o;return r.set(t,e),d.add(e),s._instrumentationIsActive||(s._instrumentationIsActive=!0,u.forEach(e=>e())),t},on:i,onCommitFiberRoot:i,onCommitFiberUnmount:i,onPostCommitFiberRoot:i,renderers:r,supportsFiber:!0,supportsFlight:!0};try{n(globalThis,`__REACT_DEVTOOLS_GLOBAL_HOOK__`,{configurable:!0,enumerable:!0,get(){return s},set(t){if(t&&typeof t==`object`){let n=s.renderers;s=t,n.size>0&&(n.forEach((e,n)=>{d.add(e),t.renderers.set(n,e)}),p(e))}}});let t=window.hasOwnProperty,r=!1;n(window,`hasOwnProperty`,{configurable:!0,value:function(...e){try{if(!r&&e[0]===`__REACT_DEVTOOLS_GLOBAL_HOOK__`)return globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__=void 0,r=!0,-0}catch{}return t.apply(this,e)},writable:!0})}catch{p(e)}return s},p=e=>{e&&u.add(e);try{let n=globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!n)return;if(!n._instrumentationSource){let e=o();if(n.checkDCE=a,n.supportsFiber=!0,n.supportsFlight=!0,n.hasUnsupportedRendererAttached=!1,n._instrumentationSource=t,n._instrumentationIsActive=!1,e||(n.on=i),n.renderers.size){n._instrumentationIsActive=!0,u.forEach(e=>e());return}let r=n.inject;if(l(n)&&!e){s=!0;let e=n.inject({scheduleRefresh(){}});e&&(n._instrumentationIsActive=!0)}n.inject=e=>{let t=r(e);return d.add(e),n._instrumentationIsActive=!0,u.forEach(e=>e()),t}}(n.renderers.size||n._instrumentationIsActive||l())&&e?.()}catch{}},m=()=>r.call(globalThis,`__REACT_DEVTOOLS_GLOBAL_HOOK__`),h=e=>m()?(p(e),globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__):f(e),g=()=>!!(typeof window<`u`&&(window.document?.createElement||window.navigator?.product===`ReactNative`)),_=()=>{try{g()&&h()}catch{}};_()})();