Skip to content

Commit

Permalink
placeholder hack
Browse files Browse the repository at this point in the history
  • Loading branch information
RobPruzan committed Nov 21, 2024
1 parent ccd75d5 commit 3bcd0af
Showing 1 changed file with 39 additions and 8 deletions.
47 changes: 39 additions & 8 deletions src/core/instrumentation/placeholder.ts
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();
}

0 comments on commit 3bcd0af

Please sign in to comment.