Repository navigation
Conversation
…oveClippedSubviews After every mounting transaction, RCTScrollViewComponentView walks its whole content with updateClippedSubviewsWithClipRect:relativeToView: (one convertRect:toView: per view). Only views with removeClippedSubviews act on that pass. RCTViewComponentView now counts those views, and _remountChildren returns early when the count is zero. Fixes react#60227 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Hi @beqramo! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Summary:
Fixes #60227. Repro: #60229.
On iOS (Fabric),
-[RCTScrollViewComponentView mountingTransactionDidMount:withSurfaceTelemetry:]calls_remountChildrenafter every mounting transaction on the surface._remountChildrensendsupdateClippedSubviewsWithClipRect:relativeToView:into the content, and the defaultUIView (ComponentViewProtocol)implementation (also used byRCTViewComponentViewwhenremoveClippedSubviewsis off) does oneconvertRect:toView:and recurses into every subview. Only anRCTViewComponentViewwithremoveClippedSubviewsacts on this pass. In an app where no view sets it, the pass walks every view under every ScrollView and changes nothing. With a large tree and a commit every frame (Reanimated UI-thread commits, or back-to-back React commits), this is seconds of main-thread time: our production app reports 5–6 s main-thread hangs and MetricKit CPU exceptions with this exact stack, mostly on iPads.This change:
RCTViewComponentViewkeeps a count of views with_removeClippedSubviewsset. All writes go through one setter, so the count follows prop changes,prepareForRecycle, and deallocation.+anyViewRemovesClippedSubviewsexposes it.RCTScrollViewComponentView._remountChildrenreturns early when the count is zero. When any view hasremoveClippedSubviews, the pass runs exactly as before, so clipping behavior does not change.Alternatives considered:
_remountChildrenfrommountingTransactionDidMountonly when the transaction has mutations under this ScrollView. That needs a subtree lookup per transaction and still walks everything for unrelated changes inside the ScrollView.removeClippedSubviewskeep today's behavior.Notes:
RCTViewuses a different selector (react_updateClippedSubviewsWithClipRect:relativeToView:), so legacy-interop views are not reached by this pass today either.RCTViewComponentView.h. If you would rather not grow the public header, it can move to a private header.Changelog:
[IOS] [FIXED] - Skip the ScrollView clipping pass after each mounting transaction when no view uses
removeClippedSubviewsTest Plan:
Unit tests (added, run locally):
RCTViewComponentViewTeststestAnyViewRemovesClippedSubviewsFollowsPropsRecyclingAndDeallocation: the count follows props on, recycle, props on again, and deallocation.RCTScrollViewComponentViewTeststestClippingPassRunsOnlyWhenAViewRemovesClippedSubviews: scrolling past the clipping leeway does not callupdateClippedSubviewsWithClipRect:on content when no view clips, and does once a view hasremoveClippedSubviews.These files belong to the
Teststest spec ofReact-RCTFabric.podspec, which open-source CI does not pull in, so I ran them locally: in RNTester I enabled:testspecs => ['Tests']forReact-RCTFabricinscripts/cocoapods/fabric.rband limited the spec toTests/Mounting/**/*.mm(Tests/Text/*does not compile on its own:react/renderer/element/ComponentBuilder.hnot found). Neither edit is in this PR. Thenxcodebuild test-without-building -scheme React-RCTFabric-Unit-Tests -only-testing:React-RCTFabric-Unit-Tests/RCTViewComponentViewTests -only-testing:React-RCTFabric-Unit-Tests/RCTScrollViewComponentViewTestson an iOS 26.5 simulator (Xcode 26.6):-test-iterations 3: 117/117; 5 runs in random order (classes and tests shuffled): 39/39 each. No order dependence from the shared count.Tests/Mounting: 51/51 pass.testClippingPass…(clippingPassCount1 ≠ 0); removing the decrement indealloc, or putting back_removeClippedSubviews = NOinprepareForRecycle, fails the count test.clang-format(the repo's pinned 21.1.2 viascripts/clang-format) reports no changes for all five files.On a simulator (RN 0.88.1 built from source with this patch applied, Release, iOS 26.5, iPhone 17): a ScrollView with about 4k plain views and a Reanimated
useAnimatedStyleopacity animation above it (the tree from #60229).sample <pid>for 10 s each:-[RCTMountingManager performTransaction:]updateClippedSubviewsWithClipRect:ScrollView removeClippedSubviewswith 60 rowsWith the clipping ScrollView mounted (third row), clipping still works: rows far outside the viewport are detached from the view hierarchy, and rows scrolled into view are attached again (checked by querying the native view hierarchy for the rows'
nativeIDs before and after scrolling). After unmounting it (fourth row), the count is back to zero and the pass is skipped again.The 0.88.1 patch needed one hunk adjusted by hand (
updatePropscomparesoldViewPropsthere); the code is otherwise the same as in this PR.🤖 Generated with Claude Code