Skip to content

[DevTools] Extract getDispatcherRef and fork inspectHooks() to avoid pulling React into the build artifact#36681

Open
hoxyq wants to merge 2 commits into
mainfrom
rdt-inspect-hooks-require-dispatcher
Open

[DevTools] Extract getDispatcherRef and fork inspectHooks() to avoid pulling React into the build artifact#36681
hoxyq wants to merge 2 commits into
mainfrom
rdt-inspect-hooks-require-dispatcher

Conversation

@hoxyq
Copy link
Copy Markdown
Contributor

@hoxyq hoxyq commented Jun 3, 2026

This is just a refactor to unblock the work on the Facade. This PR contains 2 changes:

  1. getDispatcherRef was extracted from fiber/renderer into its own shared module.
  2. inspectHooksOfFiber was forked. The new version specifies dispatcher as required and doesn't set it to default as ReactSharedInternals, which are pulling the whole react module as part of them:

import * as React from 'react';
const ReactSharedInternals =
React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
export default ReactSharedInternals;

hoxyq added 2 commits June 3, 2026 17:26
inspectHooks/inspectHooksOfFiber default currentDispatcher to
ReactSharedInternals, and shared/ReactSharedInternals imports React — so bundling
them drags all of React in, even for callers that always pass the renderer's
injected dispatcher (e.g. react-devtools-facade).

Extract the shared logic into private inspectHooksImpl / inspectHooksOfFiberImpl,
which require an explicit dispatcher and never reference ReactSharedInternals.
inspectHooks and inspectHooksOfFiber keep their existing behavior as thin
wrappers that supply the ReactSharedInternals default. Add exported
inspectHooksWithoutDefaultDispatcher and
inspectHooksOfFiberWithoutDefaultDispatcher that delegate to the Impls directly,
so a bundle importing only them references no React.
Move getDispatcherRef out of backend/fiber/renderer.js into
backend/shared/DevToolsReactDispatcher.js and import it back. This lets other
consumers (e.g. react-devtools-facade) reuse the renderer-dispatcher adapter
without importing the whole renderer module.
@hoxyq hoxyq requested a review from eps1lon June 3, 2026 16:34
@meta-cla meta-cla Bot added the CLA Signed label Jun 3, 2026
@react-sizebot
Copy link
Copy Markdown

Comparing: 63e95c2...468bb01

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.js = 6.84 kB 6.84 kB +0.11% 1.88 kB 1.88 kB
oss-stable/react-dom/cjs/react-dom-client.production.js = 614.26 kB 614.26 kB = 108.57 kB 108.57 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.84 kB 6.84 kB +0.11% 1.88 kB 1.88 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js = 680.19 kB 680.19 kB = 119.51 kB 119.51 kB
facebook-www/ReactDOM-prod.classic.js = 700.61 kB 700.61 kB = 123.09 kB 123.09 kB
facebook-www/ReactDOM-prod.modern.js = 690.93 kB 690.93 kB = 121.48 kB 121.48 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
oss-experimental/react-debug-tools/cjs/react-debug-tools.development.js +1.96% 33.37 kB 34.02 kB +1.25% 5.93 kB 6.00 kB
oss-stable-semver/react-debug-tools/cjs/react-debug-tools.development.js +1.96% 33.37 kB 34.02 kB +1.25% 5.93 kB 6.00 kB
oss-stable/react-debug-tools/cjs/react-debug-tools.development.js +1.96% 33.37 kB 34.02 kB +1.25% 5.93 kB 6.00 kB
oss-experimental/react-debug-tools/cjs/react-debug-tools.production.js +1.90% 29.78 kB 30.34 kB +1.26% 5.81 kB 5.88 kB
oss-stable-semver/react-debug-tools/cjs/react-debug-tools.production.js +1.90% 29.78 kB 30.34 kB +1.26% 5.81 kB 5.88 kB
oss-stable/react-debug-tools/cjs/react-debug-tools.production.js +1.90% 29.78 kB 30.34 kB +1.26% 5.81 kB 5.88 kB

Generated by 🚫 dangerJS against 468bb01

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants