New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor stack handling (no functional changes) #13165
Conversation
This makes the difference between it and ReactFiberCurrentFrame a bit clearer. ReactDebugCurrentFiber is Fiber's own implementation. ReactFiberCurrentFrame is the thing that holds a reference to the current implementation and delegates to it.
Conceptually they're very related. ReactFiberComponentTreeHook contains implementation details of reading Fiber's stack (both in DEV and PROD). ReactDebugCurrentFiber contained a reference to the current fiber, and used the above utility. It was confusing when to use which one. Colocating them makes it clearer what you could do with each method. In the future, the plan is to stop using these methods explicitly in most places, and instead delegate to a warning system that includes stacks automatically. This change makes future refactorings simpler by colocating related logic.
Details of bundled changes.Comparing: 3596e40...6b625cc react-dom
react-art
react-test-renderer
react-reconciler
react-native-renderer
Generated by 🚫 dangerJS |
ReactDebugCurrentFiber.current = null; | ||
ReactDebugCurrentFiber.phase = null; | ||
export function resetCurrentFiber() { | ||
if (__DEV__) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically this DEV block is a change, but we could never get here in PROD — if we did, the next line would crash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting - we do always check for 'DEV' before doing this, seems fine to inline the 'DEV' check.
Clarify which are DEV or PROD-only. Clarify which can return null. I believe the "work in progress only" was a mistake. I introduced it because I wasn't sure what guarantees we have around .return. But we know for sure that following a .return chain gives us an accurate stack even if we get into WIP trees because we don't have reparenting. So it's fine to relax that naming.
b4e6295
to
146ba8e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not completely DEV-only anymore. Individual methods already specify whether they work in DEV or PROD in their names.
Sure enough, putting |
1. Refactor
ReactDebugCurrentFiber
to use named exports (919d734)This makes the difference between it and
ReactFiberCurrentFrame
a bit clearer.ReactDebugCurrentFiber
is Fiber's own implementation.ReactFiberCurrentFrame
is the "isomorphic" thing that holds a reference to the current implementation and delegates to it. Note: I’m not changingReactFiberCurrentFrame
in this PR.2. Unify
ReactFiberComponentTreeHook
andReactDebugCurrentFiber
(26e0b53)Conceptually they're very related.
ReactFiberComponentTreeHook
contains implementation details of reading Fiber's stack (both in DEV and PROD).ReactDebugCurrentFiber
contained a reference to the current fiber, and usedReactFiberComponentTreeHook
to actually get its stack.In the future, the plan is to stop using these methods explicitly in most places, and instead delegate to a warning system that includes stacks automatically.
3. Rename methods to better reflect their meanings (b4e6295)
Clarify which are DEV-only, and which can be used for PROD stacks. Clarify which can return null (I opted to do it via naming because we had several bugs where we assumed it's a string).
I believe the "work in progress only" was a mistake. I introduced it because I wasn't sure what guarantees we have around
.return
. But we know for sure that following a.return
chain gives us an accurate stack even if we get into WIP trees because we don't have reparenting. So it's fine to relax that naming.This change makes future refactorings simpler by colocating related logic. We don't gain anything from having two modules (
ReactFiberComponentTreeHook
andReactDebugCurrentFiber
) that do almost exactly the same thing, but with different inputs. Its placement inshared
was also misleading because it's reconciler-specific. It was only inshared
because in the past there was Stack-related code in this file.