Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Trying to remove non-present child list" error occurred with specific use-case #35871

Closed
YangJonghun opened this issue Jan 18, 2023 · 7 comments

Comments

@YangJonghun
Copy link

Description

Trying to remove non-present child list error occurred with specific case
(please check below reproduce or example)

Version

0.71.0

Output of npx react-native info

It doesn't related with dev environment. it is JS issue
this problem occurred within react-native/Libraries/Lists/ChildListCollection.js

Steps to reproduce

  1. use FlatList(A) as ListEmptyComponent within other FlatList(B, with empty data)
  2. inject data within FlatList(B) after ListEmptyComponent mounted

Snack, code example, screenshot, or link to a repository

just render below component

const ErrorComponent = () => {
  const [data, setData] = useState<number[]>([])

  useEffect(() => {
    setTimeout(() => {
      setData([1, 2, 3, 4, 5])
    }, 2000)
  }, [])

  return (
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
      <FlatList
        data={data}
        renderItem={({ item }) => <Text>{item}</Text>}
        ListEmptyComponent={
          <FlatList data={['empty']} renderItem={({ item }) => <Text>{item}</Text>} />
        }
      />
    </View>
  )
}
@YangJonghun
Copy link
Author

@NickGerleman
Hi Nick,
this issue may occurred with below commit
010da67
if you have enough time, please check this issue. thanks😀

@NickGerleman
Copy link
Contributor

It looks like, unlike cells rendered by data, ListHeaderComponent, and ListFooterComponent, ListEmptyComponent is rendered without a CellContextProvider providing a cellKey.

This means the logic for registering/unregistering nested children does not work correctly when a VirtualizedList is present as part of ListEmptyComponent, and the new logic treats the inability to locate the registered list as an invariant violation.

There should be a relatively straightforward fix, but in the meantime a simple workaround would be to avoid nesting a FlatList as part of the ListEmptyComponent.

NickGerleman added a commit to NickGerleman/react-native that referenced this issue Jan 18, 2023
…Component

Summary:
Fixes facebook#35871

Nested VirtualizedLists register to their parents for updates, associated to a specfific cellKey set by VirtualizedListCellContextProvider. This cellKey is usually set when rendering a cell for a data item, but we can also render a nested VirtualizedList by putting one in a ListHeaderComponent/ListFooterComponent/ListEmptyComponent.

D6603342 (facebook@a010a0c) added cellKeys when we render from a header/footer, but not ListEmptyComponent, so that association would silently fail earlier.

D39466677 (facebook@010da67) added extra invariants to child list handling, that are now triggered by this case, complaining because we are trying to unregister a child list we never successfully registered, due to a missing cellKey.

This fixes the issue by providing a cellKey for ListEmptyComponent as well. It also cleans up some of the parameterization needed from when we had two VirtualizedList implementations.

Changelog:
[General][Fixed] - Fix invariant violation when nesting VirtualizedList inside ListEmptyComponent

Differential Revision: D42574462

fbshipit-source-id: 4d7817fa6298ca1ef1b0c5977f19f6b68123db8b
NickGerleman added a commit to NickGerleman/react-native that referenced this issue Jan 18, 2023
…Component (facebook#35875)

Summary:
Pull Request resolved: facebook#35875

Fixes facebook#35871

Nested VirtualizedLists register to their parents for updates, associated to a specfific cellKey set by VirtualizedListCellContextProvider. This cellKey is usually set when rendering a cell for a data item, but we can also render a nested VirtualizedList by putting one in a ListHeaderComponent/ListFooterComponent/ListEmptyComponent.

D6603342 (facebook@a010a0c) added cellKeys when we render from a header/footer, but not ListEmptyComponent, so that association would silently fail earlier.

D39466677 (facebook@010da67) added extra invariants to child list handling, that are now triggered by this case, complaining because we are trying to unregister a child list we never successfully registered, due to a missing cellKey.

This fixes the issue by providing a cellKey for ListEmptyComponent as well. It also cleans up some of the parameterization needed from when we had two VirtualizedList implementations.

Changelog:
[General][Fixed] - Fix invariant violation when nesting VirtualizedList inside ListEmptyComponent

Differential Revision: D42574462

fbshipit-source-id: dfec4981aaaa92b2525779b0f6c643688752fd04
NickGerleman added a commit to NickGerleman/react-native that referenced this issue Jan 18, 2023
…Component (facebook#35875)

Summary:
Pull Request resolved: facebook#35875

Fixes facebook#35871

Nested VirtualizedLists register to their parents for updates, associated to a specfific cellKey set by VirtualizedListCellContextProvider. This cellKey is usually set when rendering a cell for a data item, but we can also render a nested VirtualizedList by putting one in a ListHeaderComponent/ListFooterComponent/ListEmptyComponent.

D6603342 (facebook@a010a0c) added cellKeys when we render from a header/footer, but not ListEmptyComponent, so that association would silently fail earlier.

D39466677 (facebook@010da67) added extra invariants to child list handling, that are now triggered by this case, complaining because we are trying to unregister a child list we never successfully registered, due to a missing cellKey.

This fixes the issue by providing a cellKey for ListEmptyComponent as well. It also cleans up some of the parameterization needed from when we had two VirtualizedList implementations.

Changelog:
[General][Fixed] - Fix invariant violation when nesting VirtualizedList inside ListEmptyComponent

Differential Revision: D42574462

fbshipit-source-id: 496db5145616c2149584f74957fc6027c2ac0d3a
NickGerleman added a commit to NickGerleman/react-native that referenced this issue Jan 18, 2023
…Component (facebook#35875)

Summary:
Pull Request resolved: facebook#35875

Fixes facebook#35871

Nested VirtualizedLists register to their parents for updates, associated to a specfific cellKey set by VirtualizedListCellContextProvider. This cellKey is usually set when rendering a cell for a data item, but we can also render a nested VirtualizedList by putting one in a ListHeaderComponent/ListFooterComponent/ListEmptyComponent.

D6603342 (facebook@a010a0c) added cellKeys when we render from a header/footer, but not ListEmptyComponent, so that association would silently fail earlier.

D39466677 (facebook@010da67) added extra invariants to child list handling, that are now triggered by this case, complaining because we are trying to unregister a child list we never successfully registered, due to a missing cellKey.

This fixes the issue by providing a cellKey for ListEmptyComponent as well.

Changelog:
[General][Fixed] - Fix invariant violation when nesting VirtualizedList inside ListEmptyComponent

Differential Revision: D42574462

fbshipit-source-id: 99b51f891737eeb8b3b58b94aa6d4fd04a35d12d
kelset pushed a commit that referenced this issue Jan 30, 2023
…Component (#35875)

Summary:
Pull Request resolved: #35875

Fixes #35871

Nested VirtualizedLists register to their parents for updates, associated to a specfific cellKey set by VirtualizedListCellContextProvider. This cellKey is usually set when rendering a cell for a data item, but we can also render a nested VirtualizedList by putting one in a ListHeaderComponent/ListFooterComponent/ListEmptyComponent.

D6603342 (a010a0c) added cellKeys when we render from a header/footer, but not ListEmptyComponent, so that association would silently fail earlier.

D39466677 (010da67) added extra invariants to child list handling, that are now triggered by this case, complaining because we are trying to unregister a child list we never successfully registered, due to a missing cellKey.

This fixes the issue by providing a cellKey for ListEmptyComponent as well.

Changelog:
[General][Fixed] - Fix invariant violation when nesting VirtualizedList inside ListEmptyComponent

Reviewed By: christophpurrer

Differential Revision: D42574462

fbshipit-source-id: f76fa795bf471cb8a929c2efdbd814ea51927663

# Conflicts:
#	Libraries/Lists/VirtualizedList.js
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this issue May 22, 2023
…Component (facebook#35875)

Summary:
Pull Request resolved: facebook#35875

Fixes facebook#35871

Nested VirtualizedLists register to their parents for updates, associated to a specfific cellKey set by VirtualizedListCellContextProvider. This cellKey is usually set when rendering a cell for a data item, but we can also render a nested VirtualizedList by putting one in a ListHeaderComponent/ListFooterComponent/ListEmptyComponent.

D6603342 (facebook@a010a0c) added cellKeys when we render from a header/footer, but not ListEmptyComponent, so that association would silently fail earlier.

D39466677 (facebook@010da67) added extra invariants to child list handling, that are now triggered by this case, complaining because we are trying to unregister a child list we never successfully registered, due to a missing cellKey.

This fixes the issue by providing a cellKey for ListEmptyComponent as well.

Changelog:
[General][Fixed] - Fix invariant violation when nesting VirtualizedList inside ListEmptyComponent

Reviewed By: christophpurrer

Differential Revision: D42574462

fbshipit-source-id: f76fa795bf471cb8a929c2efdbd814ea51927663
@Pavi-t2s
Copy link

@YangJonghun Any fix for this error?
I'm also getting same error when i use nested Flatlist in rn 71.11

@YangJonghun
Copy link
Author

@Pavi-t2s
Unfortunately I haven't tried it with version 71.11
However, it worked fine in version 71.8

@elencho
Copy link
Contributor

elencho commented Sep 25, 2023

same issue on 71.8

@satyabrata-dash5
Copy link

Same issue on "react-native": "0.71.0",

Simulator Screenshot - iPhone 15 Pro - 2024-04-25 at 17 40 47

@sarthakpranesh
Copy link

sarthakpranesh commented Aug 28, 2024

I encountered a similar issue on RN v0.73.0 after upgrading from v0.70.12.

Our RCA was on v0.70.12 if we returned undefined value from keyExtractor for any child FlatList being rendered as item then when the items in Parent FlatList get destroyed/removed/cleaned nothing would break and FlatList will somehow manage it internally. But doing same on v0.73.0 would crash the app with Trying to remove non-present child list

So this was causing the crash on v0.73.0

const keyExtractorId = (item: any) => item?.id;

where id is undefined for a child FlatList and changing this to below fixed it

const keyExtractorId = (item: any) => `${item?.id}`;

Also got those missing IDs added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants