Skip to content

fix(native): accept SectionList refs in useScrollToTop under RN 0.87 strict types - #13221

Merged
satya164 merged 6 commits into
react-navigation:mainfrom
ErfanBagheri404:fix/use-scroll-to-top-section-list
Aug 19, 2026
Merged

satya164 merged 6 commits into
react-navigation:mainfrom
ErfanBagheri404:fix/use-scroll-to-top-section-list

Conversation

@ErfanBagheri404

@ErfanBagheri404 ErfanBagheri404 commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Problem

RN 0.87 enables the strict TypeScript API by default. ScrollView is now the component type (typeof ScrollViewWrapper), not the instance type. When a SectionList ref is passed to useScrollToTop, it falls through to the getScrollResponder() branch in ScrollableWrapper, which fails to type-check because SectionList.getScrollResponder() returns ScrollResponderType that no longer matches React.ReactNode | ScrollView.

Fix

Add scrollToLocation to the ScrollableView union so SectionList matches directly on the ScrollableView branch, avoiding the broken getScrollResponder path entirely. This also adds the runtime scrollToLocation handler in the scroll-to-top logic.

Reproduction

const ref = useRef<SectionListInstance>(null);
useScrollToTop(ref); // TS2345 before this fix

Fixes #13220

…strict types

RN 0.87 enables the strict TypeScript API by default. ScrollView is now the component type, so the getScrollResponder branch of ScrollableWrapper no longer type-checks for SectionList, which only exposes scrollToLocation and matches none of the ScrollableView members.

Add scrollToLocation to the ScrollableView union and scroll the list to the first item when a SectionList ref is passed.
@netlify

netlify Bot commented Aug 18, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for react-navigation-example ready!

Name Link
🔨 Latest commit cf29e68
🔍 Latest deploy log https://app.netlify.com/projects/react-navigation-example/deploys/6a8596f22ebcc20008aa28e3
😎 Deploy Preview https://deploy-preview-13221--react-navigation-example.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov

codecov Bot commented Aug 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.04%. Comparing base (bce29d6) to head (cf29e68).
⚠️ Report is 301 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13221      +/-   ##
==========================================
+ Coverage   72.24%   78.04%   +5.79%     
==========================================
  Files         238      263      +25     
  Lines        8391    10520    +2129     
  Branches     3480     4364     +884     
==========================================
+ Hits         6062     8210    +2148     
+ Misses       2274     2247      -27     
- Partials       55       63       +8     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@satya164 satya164 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thanks for the pr. i have a couple of changes

@@ -0,0 +1,165 @@
import { expect, jest, test } from '@jest/globals';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please remove this test. it doesn't test anything useful, but exact code that was just added.

Comment thread packages/native/src/useScrollToTop.tsx Outdated
Comment on lines 17 to 120
@@ -103,6 +110,12 @@ export function useScrollToTop(ref: React.RefObject<ScrollableWrapper>) {
scrollable.scrollToOffset({ offset: 0, animated: true });
} else if ('scrollResponderScrollTo' in scrollable) {
scrollable.scrollResponderScrollTo({ y: 0, animated: true });
} else if ('scrollToLocation' in scrollable) {
scrollable.scrollToLocation({
sectionIndex: 0,
itemIndex: 0,
animated: true,
});
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

move scrollToLocation to before scrollResponderScrollTo. scrollResponderScrollTo should be the last fallback.

@satya164

Copy link
Copy Markdown
Member

from testing, it seems the only change we need is the return type of getScrollResponder. scrollToLocation may also throw for empty lists so it's not safe to call unconditionally. so I have updated the PR.

@satya164
satya164 merged commit 2396be6 into react-navigation:main Aug 19, 2026
13 checks passed
satya164 pushed a commit that referenced this pull request Aug 19, 2026
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.

RN 0.87, TypeScript – useScrollToTop no longer accepts SectionList refs

2 participants