fix: add inject() to DevTools hook so React actually calls onCommitFiberRoot
React's injectInternals() calls hook.inject(renderer) before it will ever invoke onCommitFiberRoot. When inject is missing, React's try/catch silently bails and injectedHook stays null — our handler is never reached regardless of how correctly onCommitFiberRoot is set up. Fix: define inject() on the hook we create (returns a renderer ID and stores the renderer in hook.renderers, matching the React DevTools spec). Also patches inject onto any existing stub hook that lacks it, so third-party minimal hooks don't silently block registration. This is the root cause of the 'Static HTML page' false positive on apps that don't have the React DevTools browser extension installed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
3fcfa20b32
commit
d1d5e352c8
@@ -172,8 +172,30 @@ export function buildProxyFiberHookScript(): string {
|
||||
// __REACT_DEVTOOLS_GLOBAL_HOOK__ exactly once at import time.
|
||||
var hook = window.__REACT_DEVTOOLS_GLOBAL_HOOK__;
|
||||
if (!hook) {
|
||||
hook = { renderers: new Map(), supportsFiber: true, _isDisabled: false };
|
||||
// React calls hook.inject(renderer) before it will ever call
|
||||
// onCommitFiberRoot. Without an inject method, React's injectInternals()
|
||||
// try/catch silently bails and our handler is never reached.
|
||||
var _nextRendererId = 0;
|
||||
hook = {
|
||||
renderers: new Map(),
|
||||
supportsFiber: true,
|
||||
_isDisabled: false,
|
||||
inject: function(renderer) {
|
||||
var id = ++_nextRendererId;
|
||||
hook.renderers.set(id, renderer);
|
||||
return id;
|
||||
},
|
||||
};
|
||||
window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = hook;
|
||||
} else if (typeof hook.inject !== 'function') {
|
||||
// Existing hook is missing inject (e.g. a minimal stub from another tool).
|
||||
// Patch it in so React registers properly.
|
||||
var _nextRendererId2 = 0;
|
||||
hook.inject = function(renderer) {
|
||||
var id = ++_nextRendererId2;
|
||||
hook.renderers.set(id, renderer);
|
||||
return id;
|
||||
};
|
||||
}
|
||||
|
||||
var _prevCommit = hook.onCommitFiberRoot;
|
||||
|
||||
Reference in New Issue
Block a user