Skip to content

[Bug] Horizontal LegendList can collapse to zero height after async data loads #459

@weizhe412

Description

@weizhe412

Description

A horizontal LegendList can remain collapsed to zero height when it first mounts with empty async data and later receives non-empty data.

Version

  • @legendapp/list: 3.0.0
  • React Native / Expo app
  • Import: @legendapp/list/react-native

Reproduction

A simplified version of the pattern:

const [data, setData] = React.useState<Item[]>([]);

React.useEffect(() => {
  setTimeout(() => {
    setData([
      { id: "1", title: "City 1" },
      { id: "2", title: "City 2" },
    ]);
  }, 1000);
}, []);

return (
  <View>
    <Text>Popular cities</Text>
    <LegendList
      horizontal
      recycleItems
      data={data}
      keyExtractor={(item) => item.id}
      showsHorizontalScrollIndicator={false}
      renderItem={({ item }) => (
        <Pressable style={{ width: 220, height: 275, backgroundColor: "#eee" }}>
          <Text>{item.title}</Text>
        </Pressable>
      )}
      ListEmptyComponent={
        <View style={{ flexDirection: "row", gap: 16 }}>
          <View style={{ width: 220, height: 275, backgroundColor: "#eee" }} />
          <View style={{ width: 220, height: 275, backgroundColor: "#eee" }} />
        </View>
      }
    />
  </View>
);

Expected behavior

After data changes from empty to non-empty, the horizontal list should measure rendered items and set its cross-axis height to the maximum item height, e.g. 275px.

Actual behavior

The horizontal list remains collapsed / visually has no height after async data arrives, even though items have explicit height.

Notes

If the same horizontal list mounts with non-empty data on the first render, height is measured correctly. If the list itself is given an explicit height, it also renders correctly.

This makes async horizontal carousels difficult to use without adding an explicit list height or delaying mounting until data is ready.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions