Skip to content
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

Merged
merged 4 commits into from Jul 7, 2018

Conversation

gaearon
Copy link
Collaborator

@gaearon gaearon commented Jul 6, 2018

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 changing ReactFiberCurrentFrame in this PR.

2. Unify ReactFiberComponentTreeHook and ReactDebugCurrentFiber (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 used ReactFiberComponentTreeHook 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 and ReactDebugCurrentFiber) that do almost exactly the same thing, but with different inputs. Its placement in shared was also misleading because it's reconciler-specific. It was only in shared because in the past there was Stack-related code in this file.

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.
@pull-bot
Copy link

pull-bot commented Jul 6, 2018

Details of bundled changes.

Comparing: 3596e40...6b625cc

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.development.js -0.2% -0.2% 639.88 KB 638.51 KB 149.82 KB 149.58 KB UMD_DEV
react-dom.development.js -0.2% -0.2% 636 KB 634.64 KB 148.63 KB 148.39 KB NODE_DEV
ReactDOM-dev.js -0.2% -0.1% 642.2 KB 640.9 KB 146.95 KB 146.75 KB FB_WWW_DEV
ReactDOM-prod.js 🔺+0.5% 🔺+0.2% 274.96 KB 276.33 KB 51.58 KB 51.7 KB FB_WWW_PROD
ReactDOM-profiling.js +0.5% +0.2% 277.99 KB 279.33 KB 52.26 KB 52.35 KB FB_WWW_PROFILING

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-art.development.js -0.3% -0.2% 424.58 KB 423.19 KB 95.5 KB 95.33 KB UMD_DEV
react-art.development.js -0.2% -0.1% 356.55 KB 355.74 KB 78.37 KB 78.26 KB NODE_DEV
ReactART-dev.js -0.2% -0.1% 345.58 KB 344.86 KB 73.13 KB 73.05 KB FB_WWW_DEV
ReactART-prod.js 🔺+0.7% 🔺+0.2% 146.19 KB 147.23 KB 24.88 KB 24.93 KB FB_WWW_PROD

react-test-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-test-renderer.development.js -0.2% -0.1% 360.63 KB 359.81 KB 78.85 KB 78.74 KB UMD_DEV
react-test-renderer.development.js -0.2% -0.1% 356.75 KB 355.93 KB 77.89 KB 77.78 KB NODE_DEV
ReactTestRenderer-dev.js -0.2% -0.1% 360.63 KB 359.9 KB 76.72 KB 76.64 KB FB_WWW_DEV

react-reconciler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-reconciler.development.js -0.2% -0.1% 344.94 KB 344.12 KB 74.28 KB 74.17 KB NODE_DEV
react-reconciler-persistent.development.js -0.2% -0.1% 343.55 KB 342.74 KB 73.72 KB 73.62 KB NODE_DEV

react-native-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactNativeRenderer-dev.js -0.1% -0.1% 479.09 KB 478.42 KB 105.78 KB 105.72 KB RN_FB_DEV
ReactNativeRenderer-prod.js 🔺+0.5% 🔺+0.1% 211.13 KB 212.26 KB 36.88 KB 36.92 KB RN_FB_PROD
ReactNativeRenderer-dev.js -0.1% -0.1% 478.83 KB 478.15 KB 105.72 KB 105.66 KB RN_OSS_DEV
ReactNativeRenderer-prod.js 🔺+0.5% 🔺+0.1% 201.01 KB 202.11 KB 35.3 KB 35.34 KB RN_OSS_PROD
ReactFabric-dev.js -0.2% -0.1% 469.37 KB 468.64 KB 103.37 KB 103.3 KB RN_FB_DEV
ReactFabric-prod.js 🔺+0.4% 🔺+0.2% 192.19 KB 193.03 KB 33.71 KB 33.76 KB RN_FB_PROD
ReactFabric-dev.js -0.2% -0.1% 469.41 KB 468.68 KB 103.39 KB 103.31 KB RN_OSS_DEV
ReactFabric-prod.js 🔺+0.4% 🔺+0.2% 192.22 KB 193.07 KB 33.72 KB 33.77 KB RN_OSS_PROD
ReactNativeRenderer-profiling.js +0.6% +0.1% 204.1 KB 205.23 KB 35.97 KB 36.02 KB RN_OSS_PROFILING
ReactFabric-profiling.js +0.4% +0.1% 195.01 KB 195.84 KB 34.33 KB 34.38 KB RN_OSS_PROFILING
ReactNativeRenderer-profiling.js +0.5% +0.1% 214.18 KB 215.35 KB 37.57 KB 37.61 KB RN_FB_PROFILING
ReactFabric-profiling.js +0.4% +0.1% 194.97 KB 195.8 KB 34.31 KB 34.36 KB RN_FB_PROFILING

Generated by 🚫 dangerJS

@gaearon gaearon changed the title Unify ReactFiberComponentTreeHook and ReactDebugCurrentFiber Refactor stack handling (no functional changes) Jul 6, 2018
ReactDebugCurrentFiber.current = null;
ReactDebugCurrentFiber.phase = null;
export function resetCurrentFiber() {
if (__DEV__) {
Copy link
Collaborator Author

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.

Copy link
Contributor

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.
Copy link
Contributor

@flarnie flarnie left a comment

Choose a reason for hiding this comment

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

Thanks for working on this!

cat_its_beautiful

It's not completely DEV-only anymore.
Individual methods already specify whether they work in DEV or PROD in their names.
@gaearon
Copy link
Collaborator Author

gaearon commented Jul 7, 2018

Sure enough, putting OrNull() in the method name helped uncover a few places where we expect it to be a string. Will fix in a follow-up PR since this one doesn't change the logic.

@gaearon gaearon merged commit 5662595 into facebook:master Jul 7, 2018
@gaearon gaearon deleted the refactor-some-stuff branch July 7, 2018 00:09
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.

None yet

4 participants