[DevTools] Extract getDispatcherRef and fork inspectHooks() to avoid pulling React into the build artifact#36681
Open
hoxyq wants to merge 2 commits into
Open
[DevTools] Extract getDispatcherRef and fork inspectHooks() to avoid pulling React into the build artifact#36681hoxyq wants to merge 2 commits into
hoxyq wants to merge 2 commits into
Conversation
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.
|
Comparing: 63e95c2...468bb01 Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: Expand to show
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is just a refactor to unblock the work on the Facade. This PR contains 2 changes:
getDispatcherRefwas extracted fromfiber/rendererinto its own shared module.inspectHooksOfFiberwas forked. The new version specifies dispatcher as required and doesn't set it to default asReactSharedInternals, which are pulling the wholereactmodule as part of them:react/packages/shared/ReactSharedInternals.js
Lines 10 to 15 in 63e95c2