Skip to content

Fix VirtualizedSectionList.scrollToLocation off-by-one and sticky header offset (#58329) - #58329

Open
amroaltah wants to merge 1 commit into
react:mainfrom
amroaltah:fix-virtualizedsectionlist-scrolltolocation
Open

Fix VirtualizedSectionList.scrollToLocation off-by-one and sticky header offset (#58329)#58329
amroaltah wants to merge 1 commit into
react:mainfrom
amroaltah:fix-virtualizedsectionlist-scrolltolocation

Conversation

@amroaltah

@amroaltah amroaltah commented Sep 4, 2026

Copy link
Copy Markdown

Summary:

VirtualizedSectionList.scrollToLocation, and SectionList through its wrapper, mapped itemIndex to the underlying flat list without skipping the section header. As a result, itemIndex: 0 targeted the header and every other item was one row early. Sticky-header compensation was also skipped for the first item, allowing the header to obscure it.

This change adds the header row to the flattened target index and always applies the sticky-header offset using the current section header metrics. The public API remains zero-based, but callers that compensated for the old behavior must remove that compensation.

Migration:

  • Replace itemIndex: n + 1 workarounds with itemIndex: n.
  • Replace itemIndex: data.length last-item workarounds with itemIndex: data.length - 1.

Thanks to Marc Rousavy (mrousavy) for the diagnosis: #50143

Changelog:
[General][Breaking] - Fix SectionList and VirtualizedSectionList scrollToLocation to account for section headers and sticky headers correctly.

Differential Revision: D118547738

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 4, 2026
@facebook-github-tools facebook-github-tools Bot added p: Facebook Partner: Facebook Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Sep 4, 2026
…der offset (react#58329)

Summary:

`VirtualizedSectionList.scrollToLocation`, and `SectionList` through its wrapper, mapped `itemIndex` to the underlying flat list without skipping the section header. As a result, `itemIndex: 0` targeted the header and every other item was one row early. Sticky-header compensation was also skipped for the first item, allowing the header to obscure it.

This change adds the header row to the flattened target index and always applies the sticky-header offset using the current section header metrics. The public API remains zero-based, but callers that compensated for the old behavior must remove that compensation.

Migration:
- Replace `itemIndex: n + 1` workarounds with `itemIndex: n`.
- Replace `itemIndex: data.length` last-item workarounds with `itemIndex: data.length - 1`.

Thanks to Marc Rousavy (mrousavy) for the diagnosis: react#50143

Changelog:
[General][Breaking] - Fix `SectionList` and `VirtualizedSectionList` `scrollToLocation` to account for section headers and sticky headers correctly.

Differential Revision: D118547738
@meta-codesync meta-codesync Bot changed the title [RN] Fix VirtualizedSectionList.scrollToLocation off-by-one and sticky header offset Fix VirtualizedSectionList.scrollToLocation off-by-one and sticky header offset (#58329) Sep 8, 2026
@amroaltah
amroaltah force-pushed the fix-virtualizedsectionlist-scrolltolocation branch from 69206a9 to a5bb9b2 Compare September 8, 2026 20:32
@meta-codesync

meta-codesync Bot commented Sep 8, 2026

Copy link
Copy Markdown

@amroaltah has exported this pull request. If you are a Meta employee, you can view the originating Diff in D118547738.

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

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. meta-exported p: Facebook Partner: Facebook Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant