Skip to content

Don't call VirtualizedList's onLayout with the ListEmptyComponent's layout - #60149

Open
kagantemizkan wants to merge 2 commits into
react:mainfrom
kagantemizkan:fix/virtualized-list-empty-onlayout
Open

kagantemizkan wants to merge 2 commits into
react:mainfrom
kagantemizkan:fix/virtualized-list-empty-onlayout

Conversation

@kagantemizkan

Copy link
Copy Markdown

Summary:

When the list is empty, VirtualizedList calls the list's onLayout twice: once from the ScrollView with the list's own frame, and once from _onLayoutEmpty with the frame of ListEmptyComponent. The second call reports the empty component's position and size inside the content container, so code that sizes things from the list's width (columns, tile sizes) picks up the wrong width whenever the empty component has a margin or padding.

_onLayoutEmpty came in with ListEmptyComponent in 2017 (264d67c). The header and footer handlers next to it store their own length; the empty one only forwards its event to props.onLayout, which looks unintended. This removes it. The empty component's own onLayout is still called.

Changelog:

[GENERAL] [FIXED] - VirtualizedList (and FlatList/SectionList) no longer calls onLayout with the layout of ListEmptyComponent

Test Plan:

  • Added a test to VirtualizedList-test.js: the list's onLayout is not called when the empty component lays out. It fails on main (1 call, expected 0) and passes with this change. The whole file passes (89 passed, 1 skipped), and flow full-check, ESLint and Prettier are clean.
  • iOS simulator, RN 0.88.1: an empty FlatList with margin: 8 and a ListEmptyComponent with margin: 24, logging every onLayout call:
list onLayout calls
empty, before x=8 y=221 w=386 h=464, then x=24 y=24 w=338 h=66
empty, after x=8 y=221 w=386 h=464 only; the empty component's own onLayout still gets x=24 y=24 w=338 h=66
one item (before and after) x=8 y=221 w=386 h=464 only

…ayout

When the list is empty, VirtualizedList called the list's onLayout twice:
once from the ScrollView with the list's own frame, and once from
_onLayoutEmpty with the frame of ListEmptyComponent. Remove
_onLayoutEmpty; the empty component's own onLayout is still called.
@meta-cla

meta-cla Bot commented Nov 19, 2026

Copy link
Copy Markdown

Hi @kagantemizkan!

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!

@meta-cla

meta-cla Bot commented Nov 19, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@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 Nov 19, 2026
@meta-cla

meta-cla Bot commented Nov 19, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Nov 19, 2026
Comment on lines 1155 to 1160

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's no longer necessary to override this now, you can remove this completely,

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done in 80ae7a1: the onLayout override is gone, so the clone only adds the inversion style (still needed for inverted lists; Fragments are still returned as is). I updated the tests too: the cloned element no longer gets an onLayout, and the new test checks that the empty component's own onLayout still runs while the list's doesn't.

cloneElement keeps the element's own onLayout, so the wrapper is no
longer needed now that it only called that handler.
@meta-codesync

meta-codesync Bot commented Nov 19, 2026

Copy link
Copy Markdown

@javache has imported this pull request. If you are a Meta employee, you can view this in D133240954.

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

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. 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.

2 participants