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

[Fiber] Unify Hook Unmounting into ReactFiberCommitEffects #30979

Closed
wants to merge 1 commit into from

Conversation

sebmarkbage
Copy link
Collaborator

@sebmarkbage sebmarkbage commented Sep 16, 2024

This moves the recording wrapper around commitHookEffectListUnmount into a commitHookLayoutUnmountEffects helper in ReactFiberCommitEffects so that all layout effect recording moves in there. This was already how mounts worked with the commitHookLayoutMountEffects helper.

The main thing here is that I now use this helper in the deletion code a Fiber that has Hooks that need to unmount. This code doesn't need to be forked instead we can all the unmounting code once for insertion effects and once for layout effects. That way the code can be unified.

The main behavior change here is that all insertion effects of a Hook unmount first and then all layout effects. That's fix to the behavior because that's how the mount and update phases already work and that's consistent with how we treat other unmounts in separate phases. The downside is perhaps that we have to loop over the list of Hooks even though most likely there won't be any insertion effects in that list. That's what we already do for updates and mounts though.

Copy link

vercel bot commented Sep 16, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-compiler-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 17, 2024 7:34pm

@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Sep 16, 2024
}
}
if (
enableHiddenSubtreeInsertionEffectCleanup ||
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Now this flag is a bit simpler.

@react-sizebot
Copy link

Comparing: a99d8e8...f17f09b

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 = 1.82 kB 1.82 kB
oss-stable/react-dom/cjs/react-dom-client.production.js = 509.31 kB 508.45 kB = 91.10 kB 91.00 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.69 kB 6.69 kB +0.05% 1.83 kB 1.83 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js = 514.23 kB 513.40 kB = 91.81 kB 91.72 kB
facebook-www/ReactDOM-prod.classic.js = 604.86 kB 602.73 kB = 106.86 kB 106.68 kB
facebook-www/ReactDOM-prod.modern.js = 581.13 kB 579.03 kB = 103.01 kB 102.80 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
react-native/implementations/ReactNativeRenderer-prod.js = 360.77 kB 360.05 kB = 63.13 kB 63.02 kB
oss-experimental/react-reconciler/cjs/react-reconciler.production.js = 389.95 kB 389.13 kB = 63.93 kB 63.77 kB
oss-stable/react-reconciler/cjs/react-reconciler.production.js = 384.87 kB 384.05 kB = 63.11 kB 62.95 kB
oss-stable-rc/react-reconciler/cjs/react-reconciler.production.js = 384.84 kB 384.03 kB = 63.08 kB 62.93 kB
oss-stable-semver/react-reconciler/cjs/react-reconciler.production.js = 384.84 kB 384.03 kB = 63.08 kB 62.93 kB
oss-stable/react-dom/cjs/react-dom-profiling.development.js = 957.25 kB 955.16 kB = 162.01 kB 161.68 kB
oss-stable-rc/react-dom/cjs/react-dom-profiling.development.js = 957.15 kB 955.05 kB = 161.99 kB 161.66 kB
oss-stable-semver/react-dom/cjs/react-dom-profiling.development.js = 957.15 kB 955.05 kB = 161.99 kB 161.66 kB
oss-stable/react-dom/cjs/react-dom-client.development.js = 940.81 kB 938.72 kB = 159.18 kB 158.85 kB
oss-stable-rc/react-dom/cjs/react-dom-client.development.js = 940.71 kB 938.62 kB = 159.16 kB 158.83 kB
oss-stable-semver/react-dom/cjs/react-dom-client.development.js = 940.71 kB 938.62 kB = 159.16 kB 158.83 kB
facebook-react-native/react-test-renderer/cjs/ReactTestRenderer-prod.js = 323.96 kB 323.21 kB = 57.03 kB 56.94 kB
oss-experimental/react-test-renderer/cjs/react-test-renderer.production.js = 309.00 kB 308.27 kB = 54.65 kB 54.55 kB
oss-stable/react-test-renderer/cjs/react-test-renderer.production.js = 306.59 kB 305.86 kB = 54.19 kB 54.09 kB
oss-stable-rc/react-test-renderer/cjs/react-test-renderer.production.js = 306.53 kB 305.80 kB = 54.17 kB 54.07 kB
oss-stable-semver/react-test-renderer/cjs/react-test-renderer.production.js = 306.53 kB 305.80 kB = 54.17 kB 54.07 kB
oss-experimental/react-dom/cjs/react-dom-profiling.profiling.js = 540.57 kB 539.23 kB = 96.44 kB 96.26 kB
oss-experimental/react-art/cjs/react-art.production.js = 304.00 kB 303.19 kB = 52.22 kB 52.12 kB
oss-stable/react-art/cjs/react-art.production.js = 299.49 kB 298.67 kB = 51.47 kB 51.38 kB
oss-stable-rc/react-art/cjs/react-art.production.js = 299.42 kB 298.61 kB = 51.45 kB 51.35 kB
oss-stable-semver/react-art/cjs/react-art.production.js = 299.42 kB 298.61 kB = 51.45 kB 51.35 kB
oss-experimental/react-reconciler/cjs/react-reconciler.development.js = 641.18 kB 639.38 kB = 103.15 kB 102.89 kB
oss-stable/react-dom/cjs/react-dom-profiling.profiling.js = 540.57 kB 539.01 kB = 96.10 kB 95.86 kB
oss-stable-rc/react-dom/cjs/react-dom-profiling.profiling.js = 540.46 kB 538.91 kB = 96.08 kB 95.84 kB
oss-stable-semver/react-dom/cjs/react-dom-profiling.profiling.js = 540.46 kB 538.91 kB = 96.08 kB 95.84 kB
react-native/implementations/ReactFabric-dev.js = 631.98 kB 629.98 kB = 103.47 kB 103.20 kB
react-native/implementations/ReactNativeRenderer-dev.js = 643.17 kB 641.12 kB = 105.52 kB 105.25 kB
oss-experimental/react-art/cjs/react-art.development.js = 559.59 kB 557.80 kB = 90.60 kB 90.41 kB
oss-stable/react-reconciler/cjs/react-reconciler.development.js = 637.75 kB 635.70 kB = 102.44 kB 102.12 kB
oss-stable-rc/react-reconciler/cjs/react-reconciler.development.js = 637.73 kB 635.68 kB = 102.42 kB 102.10 kB
oss-stable-semver/react-reconciler/cjs/react-reconciler.development.js = 637.73 kB 635.68 kB = 102.42 kB 102.10 kB
oss-experimental/react-test-renderer/cjs/react-test-renderer.development.js = 550.41 kB 548.59 kB = 89.93 kB 89.69 kB
oss-stable/react-test-renderer/cjs/react-test-renderer.development.js = 547.84 kB 546.03 kB = 89.54 kB 89.29 kB
oss-stable-rc/react-test-renderer/cjs/react-test-renderer.development.js = 547.78 kB 545.96 kB = 89.52 kB 89.27 kB
oss-stable-semver/react-test-renderer/cjs/react-test-renderer.development.js = 547.78 kB 545.96 kB = 89.52 kB 89.27 kB
oss-experimental/react-reconciler/cjs/react-reconciler.profiling.js = 411.54 kB 410.17 kB = 67.43 kB 67.23 kB
facebook-www/ReactDOMTesting-prod.classic.js = 619.60 kB 617.50 kB = 110.57 kB 110.38 kB
facebook-www/ReactTestRenderer-dev.classic.js = 575.18 kB 573.22 kB = 94.01 kB 93.75 kB
facebook-www/ReactTestRenderer-dev.modern.js = 575.17 kB 573.22 kB = 94.01 kB 93.75 kB
facebook-www/ReactDOM-prod.classic.js = 604.86 kB 602.73 kB = 106.86 kB 106.68 kB
facebook-www/ReactDOMTesting-prod.modern.js = 595.86 kB 593.73 kB = 106.72 kB 106.50 kB
facebook-www/ReactDOM-prod.modern.js = 581.13 kB 579.03 kB = 103.01 kB 102.80 kB
react-native/implementations/ReactFabric-profiling.js = 376.88 kB 375.49 kB = 65.36 kB 65.11 kB
oss-stable/react-art/cjs/react-art.development.js = 555.23 kB 553.18 kB = 89.82 kB 89.57 kB
oss-stable-rc/react-art/cjs/react-art.development.js = 555.16 kB 553.12 kB = 89.80 kB 89.55 kB
oss-stable-semver/react-art/cjs/react-art.development.js = 555.16 kB 553.12 kB = 89.80 kB 89.55 kB
react-native/implementations/ReactNativeRenderer-profiling.js = 386.57 kB 385.12 kB = 67.16 kB 66.91 kB
facebook-react-native/react-test-renderer/cjs/ReactTestRenderer-dev.js = 581.18 kB 579.00 kB = 94.66 kB 94.38 kB
facebook-www/ReactDOMTesting-dev.classic.js = 1,107.60 kB 1,103.36 kB = 186.53 kB 186.08 kB
facebook-www/ReactDOM-dev.classic.js = 1,090.70 kB 1,086.47 kB = 182.57 kB 182.12 kB
oss-stable/react-reconciler/cjs/react-reconciler.profiling.js = 411.74 kB 410.13 kB = 66.98 kB 66.73 kB
oss-stable-rc/react-reconciler/cjs/react-reconciler.profiling.js = 411.72 kB 410.11 kB = 66.96 kB 66.70 kB
oss-stable-semver/react-reconciler/cjs/react-reconciler.profiling.js = 411.72 kB 410.11 kB = 66.96 kB 66.70 kB
facebook-www/ReactDOMTesting-dev.modern.js = 1,071.72 kB 1,067.49 kB = 180.50 kB 180.01 kB
facebook-www/ReactDOM-dev.modern.js = 1,054.86 kB 1,050.58 kB = 176.62 kB 176.14 kB
facebook-react-native/react-test-renderer/cjs/ReactTestRenderer-profiling.js = 346.37 kB 344.93 kB = 60.33 kB 60.11 kB
react-native/implementations/ReactFabric-prod.fb.js = 380.79 kB 379.14 kB = 66.29 kB 66.12 kB
facebook-www/ReactReconciler-prod.classic.js = 464.29 kB 462.21 kB = 75.11 kB 74.94 kB
facebook-www/ReactReconciler-prod.modern.js = 445.51 kB 443.43 kB = 72.30 kB 72.13 kB
react-native/implementations/ReactNativeRenderer-prod.fb.js = 386.66 kB 384.80 kB = 67.55 kB 67.34 kB
facebook-www/ReactART-prod.classic.js = 371.37 kB 369.49 kB = 62.77 kB 62.54 kB
facebook-www/ReactART-prod.modern.js = 354.34 kB 352.46 kB = 60.01 kB 59.76 kB
facebook-www/ReactDOM-profiling.classic.js = 634.60 kB 631.13 kB = 111.13 kB 110.77 kB
react-native/implementations/ReactFabric-dev.fb.js = 662.05 kB 658.37 kB = 108.02 kB 107.64 kB
facebook-www/ReactReconciler-dev.classic.js = 744.70 kB 740.51 kB = 118.53 kB 118.08 kB
facebook-www/ReactDOM-profiling.modern.js = 610.25 kB 606.72 kB = 107.14 kB 106.74 kB
facebook-www/ReactReconciler-dev.modern.js = 720.81 kB 716.62 kB = 114.45 kB 113.94 kB
react-native/implementations/ReactNativeRenderer-dev.fb.js = 669.66 kB 665.61 kB = 109.58 kB 109.08 kB
facebook-www/ReactART-dev.classic.js = 658.22 kB 654.01 kB = 105.27 kB 104.76 kB
facebook-www/ReactART-dev.modern.js = 635.75 kB 631.53 kB = 101.60 kB 101.06 kB
react-native/implementations/ReactFabric-profiling.fb.js = 407.43 kB 404.54 kB = 70.43 kB 70.12 kB
react-native/implementations/ReactNativeRenderer-profiling.fb.js = 413.36 kB 410.19 kB = 71.64 kB 71.24 kB

Generated by 🚫 dangerJS against f5775d7

sebmarkbage added a commit that referenced this pull request Sep 17, 2024
…ct Duration in Module Scope (#30981)

Stacked on #30979.

The problem with the previous approach is that it recursively walked the
tree up to propagate the resulting time from recording a layout effect.

Instead, we keep a running count of the effect duration on the module
scope. Then we reset it when entering a nested Profiler and then we add
its elapsed count when we exit the Profiler.

This also fixes a bug where we weren't previously including unmount
times for some detached trees since they couldn't bubble up to find the
profiler.
github-actions bot pushed a commit that referenced this pull request Sep 17, 2024
…ct Duration in Module Scope (#30981)

Stacked on #30979.

The problem with the previous approach is that it recursively walked the
tree up to propagate the resulting time from recording a layout effect.

Instead, we keep a running count of the effect duration on the module
scope. Then we reset it when entering a nested Profiler and then we add
its elapsed count when we exit the Profiler.

This also fixes a bug where we weren't previously including unmount
times for some detached trees since they couldn't bubble up to find the
profiler.

DiffTrain build for commit 4549be0.
github-actions bot pushed a commit that referenced this pull request Sep 17, 2024
…ct Duration in Module Scope (#30981)

Stacked on #30979.

The problem with the previous approach is that it recursively walked the
tree up to propagate the resulting time from recording a layout effect.

Instead, we keep a running count of the effect duration on the module
scope. Then we reset it when entering a nested Profiler and then we add
its elapsed count when we exit the Profiler.

This also fixes a bug where we weren't previously including unmount
times for some detached trees since they couldn't bubble up to find the
profiler.

DiffTrain build for [4549be0](4549be0)
@sebmarkbage
Copy link
Collaborator Author

Landed by #30981.

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.

3 participants