Skip to content

Commit 3bcd0af

Browse files
committed
placeholder hack
1 parent ccd75d5 commit 3bcd0af

File tree

1 file changed

+39
-8
lines changed

1 file changed

+39
-8
lines changed
Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,42 @@
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+
}

0 commit comments

Comments
 (0)