From d1d5e352c8a85cacdb179181df0212721a462c13 Mon Sep 17 00:00:00 2001 From: SinachPat Date: Thu, 7 May 2026 14:04:29 +0100 Subject: [PATCH] fix: add inject() to DevTools hook so React actually calls onCommitFiberRoot MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- packages/renderer/src/fiber-hook.ts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/renderer/src/fiber-hook.ts b/packages/renderer/src/fiber-hook.ts index 5eeba34..5ac3747 100644 --- a/packages/renderer/src/fiber-hook.ts +++ b/packages/renderer/src/fiber-hook.ts @@ -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;