react / react/react-native

SectionList ListHeaderComponent gets rerendered when sections data changes

Open
#23,400 8 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Component: SectionList Ran Commands
Dominant language
C++
Stars
127k
Forks
25.3k
Avg merge
1d 23h
Merged PRs (30d)
4

Description

🐛 Bug Report

This is a duplicate of:
https://github.com/facebook/react-native/issues/16824
https://github.com/facebook/react-native/issues/16823
https://github.com/facebook/react-native/issues/14249

But since those 3 were closed and they are missing a reproducible example of the bug I'm reopening.

Description

If one uses a TextInput as a ListHeaderComponent when searching and when the returned sections are empty the TextInput loses focus.

If when searching the sections still have data - then the TextInput in the ListHeaderComponent doesn't lose focus.

To Reproduce

https://snack.expo.io/H12h3BgHV

Expected Behavior

I would expect for the TextInput not to lose focus

Code Example

https://snack.expo.io/H12h3BgHV

Environment

[skip envinfo]
RN 0.58

I've been trying to debug this with @pawelczerepak and what we noticed is that VirtualizedCellWrapper
https://github.com/facebook/react-native/blob/master/Libraries/Lists/VirtualizedList.js#L1759
gets unmounted and mounted when sections is an empty array. And when this happens everything inside of it gets unmounted and mounted again.
@sahrens - any ideas on what might be going on here?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the focus loss with the Snack example, then inspect the VirtualizedCellWrapper code around Libraries/Lists/VirtualizedList.js line 1759. Trace why it unmounts and mounts when sections becomes empty, and verify that the TextInput in ListHeaderComponent remains focused while section data changes.

Written by the indexing model from the issue text.

Assessment

Tech stack
react-native
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.