File tree Expand file tree Collapse file tree 1 file changed +39
-8
lines changed Expand file tree Collapse file tree 1 file changed +39
-8
lines changed Original file line number Diff line number Diff line change 1- import { registerDevtoolsHook } from './fiber' ;
2-
31// __REACT_DEVTOOLS_GLOBAL_HOOK__ must exist before React is ever executed
42// this is the case with the React Devtools extension, but without it, we need
53
6- // sometimes in expo this comes back as undefined
7- // registerDevtoolsHook({
8- // onCommitFiberRoot() {
9- // /**/
10- // },
11- // });
4+ let attemptCount = 0 ;
5+ const MAX_ATTEMPTS = 3 ;
6+
7+ // temporary hack since module is sometime uninitialized in expo
8+ // fix is probably to remove circular imports
9+ function ensureDevtoolsHook ( ) {
10+ return new Promise ( ( resolve ) => {
11+ function attempt ( ) {
12+ try {
13+ const { registerDevtoolsHook } = require ( './fiber' ) ;
14+ if ( registerDevtoolsHook ) {
15+ registerDevtoolsHook ( {
16+ onCommitFiberRoot ( ) {
17+ /**/
18+ } ,
19+ } ) ;
20+ resolve ( true ) ;
21+ } else if ( attemptCount < MAX_ATTEMPTS ) {
22+ attemptCount ++ ;
23+ setTimeout ( attempt , 50 ) ;
24+ } else {
25+ resolve ( false ) ;
26+ }
27+ } catch ( e ) {
28+ if ( attemptCount < MAX_ATTEMPTS ) {
29+ attemptCount ++ ;
30+ setTimeout ( attempt , 50 ) ;
31+ } else {
32+ resolve ( false ) ;
33+ }
34+ }
35+ }
36+ attempt ( ) ;
37+ } ) ;
38+ }
39+
40+ if ( typeof globalThis . __REACT_DEVTOOLS_GLOBAL_HOOK__ === 'undefined' ) {
41+ ensureDevtoolsHook ( ) ;
42+ }
You can’t perform that action at this time.
0 commit comments