Skip to content

Fix ScrollView callback ref cleanup - #60139

Open
charan-rathore wants to merge 1 commit into
react:mainfrom
charan-rathore:fix-scrollview-callback-ref-cleanup
Open

charan-rathore wants to merge 1 commit into
react:mainfrom
charan-rathore:fix-scrollview-callback-ref-cleanup

Conversation

@charan-rathore

Copy link
Copy Markdown

Summary:

Fixes #51878.

ScrollView drops the cleanup function returned by a React 19 callback ref. On unmount or ref replacement, it calls the callback with null instead of running that cleanup.

Return a cleanup from the forwarding callback and keep each attachment's cleanup in its own closure. Call the returned cleanup when present, otherwise keep the legacy null callback. Object refs still clear on detach. Internal native/public state still clears before the caller's teardown, matching the existing detach order.

This follows the direction discussed in #52361, which closed without merging after inactivity. Thanks to @jpudysz for the report and @ScypyonX for the earlier work.

Changelog:

[GENERAL] [FIXED] - ScrollView runs cleanup functions returned by callback refs.

Test Plan:

Added Fantom regressions for both ref and innerViewRef:

  • cleanup on unmount, without another null callback
  • mixed cleanup, legacy and object refs through useMergeRefs, including a stable rerender
  • cleanup ordering through A to B to A replacement

On base f4f8b6a with the new tests: six failures and nine passes. With the fix: all 15 pass.

  • yarn fantom packages/react-native/Libraries/Utilities/__tests__/useMergeRefs-itest.js packages/react-native/Libraries/Components/ScrollView/__tests__/ScrollView-itest.js --runInBand --no-cache: 20 passed across two native suites.
  • yarn flow focus-check --max-workers 2 packages/react-native/Libraries/Components/ScrollView/ScrollView.js packages/react-native/Libraries/Components/ScrollView/__tests__/ScrollView-itest.js: zero errors, 1,099 files checked.
  • ESLint with --max-warnings 0, Prettier and git diff --check passed for both changed files.

Fantom ran with native Hermes/Fabric on Linux. No physical iOS/Android device, full-repository test run or performance claim. A generated Skia package-name collision warning appeared during discovery; both native suites ran and passed.

@meta-cla

meta-cla Bot commented Nov 19, 2026

Copy link
Copy Markdown

Hi @charan-rathore!

Thank you for your pull request and welcome to our community.

Action Required

In 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.

Process

In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[React 19] ScrollView cleanup function for ref is never called

2 participants