Skip to content

Using react-window-scroller causes cell components to unmount/remount #24

Description

@epurban

Hi @FedericoDiRosa , great contribution to react-window here! I'm having an issue using your library, however. It seems that introducing react-window-scroller to my implementation causes the Grid's cell components to unmount and remount whenever the parent component re-renders. This is causing a highly degraded performance. Here is the only changes in code I made:

  return (
    <div ref={ref} style={{ flex: '1 1 auto', overflow: 'hidden' }}>
      <FixedSizeGrid
        rowCount={rowCount}
        columnCount={itemsPerRow}
        rowHeight={cardWidth + cardContentHeight + GRID_GAP}
        columnWidth={cardWidth}
        height={height}
        width={gridWidth}
        overscanRowCount={4}
        itemData={itemsData}
      >
        {CardItem}
      </FixedSizeGrid>
    </div>
  );

to

  return (
    <div ref={ref} style={{ flex: '1 1 auto', overflow: 'hidden' }}>
      {/* @ts-ignore */}
      <ReactWindowScroller isGrid>
        {({ ref: gridRef, outerRef, style, onScroll }) => {
          return (
            <FixedSizeGrid
              ref={gridRef}
              outerRef={outerRef}
              style={style}
              onScroll={onScroll}
              rowCount={rowCount}
              columnCount={itemsPerRow}
              rowHeight={cardWidth + cardContentHeight + GRID_GAP}
              columnWidth={cardWidth}
              height={height}
              width={gridWidth}
              overscanRowCount={4}
              itemData={itemsData}
            >
              {CardItem}
            </FixedSizeGrid>
          );
        }}
      </ReactWindowScroller>
    </div>
  );

As you can see in the screenshot below, when I resize the window or change the width size of the parent component, the page becomes very slow due to massive amounts of unmounting and remounting:
Screen Shot 2023-01-05 at 2 59 34 PM

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions