Skip to content

Conversation

@sebmarkbage
Copy link
Collaborator

This is a nit but a Config should not have to know anything about the internals of Fibers. Ideally it shouldn't even access them but we have some cases where we need pointers back in like for this fragment.

The way we've typically abstracted this is using the ReactFiberTreeReflection helper that's in the react-reconciler. Such as in the event system.

import {
getNearestMountedFiber,
getContainerFromFiber,
getSuspenseInstanceFromFiber,
} from 'react-reconciler/src/ReactFiberTreeReflection';

We sometimes cheat but we really should clean this up such that a Fiber is actually an opaque type to the Configs and it can never dot into it without using a helper.

So this just moves traverseFragmentInstanceChildren to ReactFiberTreeReflection so that the ConfigDOM doesn't ever dot into its fields itself. It just passes the Fiber through back into the react-reconciler. I had to add a wrapper to read the .child to avoid that being assumed too. I also noticed that FragmentInstanceType is not actually passed through so that argument is unnecessary.

@react-sizebot
Copy link

Comparing: f3c9560...a73162d

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.68 kB 6.68 kB +0.05% 1.83 kB 1.83 kB
oss-stable/react-dom/cjs/react-dom-client.production.js = 518.75 kB 518.75 kB = 92.47 kB 92.47 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.69 kB 6.69 kB = 1.83 kB 1.83 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js = 591.76 kB 591.76 kB = 105.36 kB 105.36 kB
facebook-www/ReactDOM-prod.classic.js = 652.39 kB 652.28 kB = 114.72 kB 114.69 kB
facebook-www/ReactDOM-prod.modern.js = 642.71 kB 642.59 kB = 113.15 kB 113.12 kB
oss-experimental/react-reconciler/cjs/react-reconciler-reflection.development.js +9.10% 6.00 kB 6.55 kB +8.45% 1.48 kB 1.61 kB
oss-stable-semver/react-reconciler/cjs/react-reconciler-reflection.development.js +9.10% 6.00 kB 6.55 kB +8.45% 1.48 kB 1.61 kB
oss-stable/react-reconciler/cjs/react-reconciler-reflection.development.js +9.10% 6.00 kB 6.55 kB +8.45% 1.48 kB 1.61 kB
oss-experimental/react-reconciler/cjs/react-reconciler-reflection.production.js +9.09% 5.44 kB 5.93 kB +8.46% 1.48 kB 1.60 kB
oss-stable-semver/react-reconciler/cjs/react-reconciler-reflection.production.js +9.09% 5.44 kB 5.93 kB +8.46% 1.48 kB 1.60 kB
oss-stable/react-reconciler/cjs/react-reconciler-reflection.production.js +9.09% 5.44 kB 5.93 kB +8.46% 1.48 kB 1.60 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-reconciler/cjs/react-reconciler-reflection.development.js +9.10% 6.00 kB 6.55 kB +8.45% 1.48 kB 1.61 kB
oss-stable-semver/react-reconciler/cjs/react-reconciler-reflection.development.js +9.10% 6.00 kB 6.55 kB +8.45% 1.48 kB 1.61 kB
oss-stable/react-reconciler/cjs/react-reconciler-reflection.development.js +9.10% 6.00 kB 6.55 kB +8.45% 1.48 kB 1.61 kB
oss-experimental/react-reconciler/cjs/react-reconciler-reflection.production.js +9.09% 5.44 kB 5.93 kB +8.46% 1.48 kB 1.60 kB
oss-stable-semver/react-reconciler/cjs/react-reconciler-reflection.production.js +9.09% 5.44 kB 5.93 kB +8.46% 1.48 kB 1.60 kB
oss-stable/react-reconciler/cjs/react-reconciler-reflection.production.js +9.09% 5.44 kB 5.93 kB +8.46% 1.48 kB 1.60 kB
oss-experimental/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.production.js = 2,268.52 kB 2,261.18 kB = 359.01 kB 358.11 kB
oss-stable-semver/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.production.js = 2,268.31 kB 2,260.98 kB = 358.98 kB 358.08 kB
oss-stable/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.production.js = 2,268.31 kB 2,260.98 kB = 358.98 kB 358.08 kB
oss-experimental/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js = 2,595.77 kB 2,587.37 kB = 370.62 kB 369.65 kB
oss-stable-semver/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js = 2,595.58 kB 2,587.19 kB = 370.60 kB 369.62 kB
oss-stable/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js = 2,595.58 kB 2,587.19 kB = 370.60 kB 369.62 kB

Generated by 🚫 dangerJS against 4c0fb99

Copy link
Contributor

@jackpope jackpope left a comment

Choose a reason for hiding this comment

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

Make sense thanks for the refactor and explanation

@sebmarkbage sebmarkbage merged commit 6b5d9fd into facebook:main Mar 14, 2025
196 checks passed
github-actions bot pushed a commit that referenced this pull request Mar 14, 2025
…ction (#32613)

This is a nit but a Config should not have to know anything about the
internals of Fibers. Ideally it shouldn't even access them but we have
some cases where we need pointers back in like for this fragment.

The way we've typically abstracted this is using the
`ReactFiberTreeReflection` helper that's in the `react-reconciler`. Such
as in the event system.
https://github.com/facebook/react/blob/f3c956006a90dc68210bd3e19497d10fb9b028d3/packages/react-dom-bindings/src/events/ReactDOMEventListener.js#L22-L26

We sometimes cheat but we really should clean this up such that a
`Fiber` is actually an opaque type to the Configs and it can never dot
into it without using a helper.

So this just moves `traverseFragmentInstanceChildren` to
ReactFiberTreeReflection so that the ConfigDOM doesn't ever dot into its
fields itself. It just passes the Fiber through back into the
react-reconciler. I had to add a wrapper to read the `.child` to avoid
that being assumed too. I also noticed that FragmentInstanceType is not
actually passed through so that argument is unnecessary.

DiffTrain build for [6b5d9fd](6b5d9fd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed React Core Team Opened by a member of the React Core Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants