-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
39 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,42 @@ | ||
import { registerDevtoolsHook } from './fiber'; | ||
|
||
// __REACT_DEVTOOLS_GLOBAL_HOOK__ must exist before React is ever executed | ||
// this is the case with the React Devtools extension, but without it, we need | ||
|
||
// sometimes in expo this comes back as undefined | ||
// registerDevtoolsHook({ | ||
// onCommitFiberRoot() { | ||
// /**/ | ||
// }, | ||
// }); | ||
let attemptCount = 0; | ||
const MAX_ATTEMPTS = 3; | ||
|
||
// temporary hack since module is sometime uninitialized in expo | ||
// fix is probably to remove circular imports | ||
function ensureDevtoolsHook() { | ||
return new Promise((resolve) => { | ||
function attempt() { | ||
try { | ||
const { registerDevtoolsHook } = require('./fiber'); | ||
if (registerDevtoolsHook) { | ||
registerDevtoolsHook({ | ||
onCommitFiberRoot() { | ||
/**/ | ||
}, | ||
}); | ||
resolve(true); | ||
} else if (attemptCount < MAX_ATTEMPTS) { | ||
attemptCount++; | ||
setTimeout(attempt, 50); | ||
} else { | ||
resolve(false); | ||
} | ||
} catch (e) { | ||
if (attemptCount < MAX_ATTEMPTS) { | ||
attemptCount++; | ||
setTimeout(attempt, 50); | ||
} else { | ||
resolve(false); | ||
} | ||
} | ||
} | ||
attempt(); | ||
}); | ||
} | ||
|
||
if (typeof globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__ === 'undefined') { | ||
ensureDevtoolsHook(); | ||
} |