Skip to content

[DevTools] chore: extract pure functions from fiber/renderer.js#630

Closed
everettbu wants to merge 1 commit into
mainfrom
devtools/chore
Closed

[DevTools] chore: extract pure functions from fiber/renderer.js#630
everettbu wants to merge 1 commit into
mainfrom
devtools/chore

Conversation

@everettbu

Copy link
Copy Markdown

Mirror of facebook/react#35924
Original author: hoxyq


I am in a process of splitting down the renderer implementation into smaller units of logic that can be reused. This change is about extracting pure functions only.

@greptile-apps

greptile-apps Bot commented Feb 27, 2026

Copy link
Copy Markdown

Greptile Summary

This PR extracts pure functions and type definitions from the monolithic renderer.js (~400 lines removed) into four new focused modules under fiber/shared/ and one under backend/:

  • DevToolsFiberTypes.js: Type definitions (FiberInstance, VirtualInstance, FilteredFiberInstance, DevToolsInstance, SuspenseNode) and kind constants
  • DevToolsFiberChangeDetection.js: Change-detection logic (didFiberRender, getContextChanged, getChangedHooksIndices, getChangedKeys)
  • DevToolsFiberInspection.js: Inspection helpers (isError, getFiberFlags, rootSupportsProfiling, isErrorBoundary, getSecondaryEnvironmentName, areEqualRects)
  • DevToolsFiberSuspense.js: Suspense-related utilities (ioExistsInSuspenseAncestor, getAwaitInSuspendedByFromIO, getVirtualEndTime)
  • DevToolsNativeHost.js: Host/native instance utilities (getCurrentTime, getPublicInstance, getNativeTag)

Functions that previously relied on closure variables (e.g., didFiberRender and isErrorBoundary using destructured ReactTypeOfWork values) now accept an explicit workTagMap parameter, and all call sites have been updated accordingly. The Rect type in backend/types.js was exported to support the new modules. No behavioral changes.

Confidence Score: 5/5

  • This PR is a safe, mechanical refactoring that extracts pure functions with no behavioral changes.
  • The changes are purely structural: moving functions and types from one large file into smaller, focused modules. All function bodies are identical to the originals (verified via diff). Functions that depended on closure variables now explicitly receive them as parameters, and all call sites have been updated. No logic, tests, or runtime behavior has changed.
  • No files require special attention.

Important Files Changed

Filename Overview
packages/react-devtools-shared/src/backend/DevToolsNativeHost.js New file extracting pure host-related functions (getCurrentTime, getPublicInstance, getNativeTag) from renderer.js. Logic is identical to the original.
packages/react-devtools-shared/src/backend/fiber/renderer.js Large reduction (~400 lines) by extracting pure functions to new modules. All call sites updated correctly with new signatures (e.g., passing ReactTypeOfWork to didFiberRender and isErrorBoundary).
packages/react-devtools-shared/src/backend/fiber/shared/DevToolsFiberChangeDetection.js New file containing change-detection functions (didFiberRender, getContextChanged, getChangedHooksIndices, getChangedKeys, didStatefulHookChange). didFiberRender now takes a workTagMap parameter instead of relying on closure variables.
packages/react-devtools-shared/src/backend/fiber/shared/DevToolsFiberInspection.js New file containing inspection helpers (isError, getFiberFlags, rootSupportsProfiling, isErrorBoundary, getSecondaryEnvironmentName, areEqualRects). isErrorBoundary now takes workTagMap parameter instead of closure variables.
packages/react-devtools-shared/src/backend/fiber/shared/DevToolsFiberSuspense.js New file containing suspense-related pure functions (ioExistsInSuspenseAncestor, getAwaitInSuspendedByFromIO, getVirtualEndTime). Logic is identical to the original.
packages/react-devtools-shared/src/backend/fiber/shared/DevToolsFiberTypes.js New file extracting type definitions (FiberInstance, FilteredFiberInstance, VirtualInstance, DevToolsInstance, SuspenseNode) and kind constants (FIBER_INSTANCE, VIRTUAL_INSTANCE, FILTERED_FIBER_INSTANCE) from renderer.js.
packages/react-devtools-shared/src/backend/types.js Single-line change: exports the existing Rect type so it can be imported by the new extracted modules.

Last reviewed commit: 9234a9f

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

7 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@everettbu

Copy link
Copy Markdown
Author

Upstream PR was closed or merged. Code is synced via branch mirror.

@everettbu everettbu closed this Mar 3, 2026
@everettbu
everettbu deleted the devtools/chore branch March 3, 2026 13:35
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