bippy
Version:
hack into react internals
9 lines • 3.94 kB
JavaScript
/**
* @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.
*/
const e=e=>Object.assign(e,{[Symbol.dispose]:e}),t=`0.6.0`,n=`bippy-${t}`,r=Object.defineProperty,i=Object.prototype.hasOwnProperty,a=()=>{},o=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{}},s=(e=globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__)=>!!(e&&`getFiberRoots`in e);let c=!1,l;const u=(e=globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__)=>c?!0:(e&&typeof e.inject==`function`&&(l=e.inject.toString()),!!l?.includes(`(injected)`)),d=new Set,f=new Set,p=new Set,m=new WeakSet;let h=null;const g=e=>{if(e.inject===h)return;let t=e.inject,n=n=>{let r=t.call(e,n);if(!m.has(n)){m.add(n);for(let e of p)e(n)}return r};e.inject=n,h=n},_=t=>(g(x()),p.add(t),e(()=>{p.delete(t)})),v=e=>{e&&d.add(e);let t=new Map,i=0,s={_instrumentationIsActive:!1,_instrumentationSource:n,checkDCE:o,hasUnsupportedRendererAttached:!1,inject(e){let n=++i;return t.set(n,e),f.add(e),s._instrumentationIsActive||(s._instrumentationIsActive=!0,d.forEach(e=>e())),n},on:a,onCommitFiberRoot:a,onCommitFiberUnmount:a,onPostCommitFiberRoot:a,renderers:t,supportsFiber:!0,supportsFlight:!0};try{r(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)=>{f.add(e),t.renderers.set(n,e)}),y(e))}}});let t=window.hasOwnProperty,n=!1;r(window,`hasOwnProperty`,{configurable:!0,value:function(...e){try{if(!n&&e[0]===`__REACT_DEVTOOLS_GLOBAL_HOOK__`)return globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__=void 0,n=!0,-0}catch{}return t.apply(this,e)},writable:!0})}catch{y(e)}return s},y=e=>{e&&d.add(e);try{let t=globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!t)return;if(!t._instrumentationSource){t.checkDCE=o,t.supportsFiber=!0,t.supportsFlight=!0,t.hasUnsupportedRendererAttached=!1,t._instrumentationSource=n,t._instrumentationIsActive=!1;let e=s(t);if(e||(t.on=a),t.renderers.size){t._instrumentationIsActive=!0,d.forEach(e=>e());return}let r=t.inject,i=u(t);i&&!e&&(c=!0,t.inject({scheduleRefresh(){}})&&(t._instrumentationIsActive=!0)),t.inject=e=>{let n=r(e);return f.add(e),i&&t.renderers.set(n,e),t._instrumentationIsActive=!0,d.forEach(e=>e()),n}}(t.renderers.size||t._instrumentationIsActive||u())&&e?.()}catch{}},b=()=>i.call(globalThis,`__REACT_DEVTOOLS_GLOBAL_HOOK__`),x=e=>b()?(y(e),globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__):v(e),S=()=>!!(typeof window<`u`&&(window.document?.createElement||window.navigator?.product===`ReactNative`)),C=()=>{try{S()&&x()}catch{}};Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`m`,{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return _}});