question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Two <WindowScroller>s on a page causes the second one to not render properly

See original GitHub issue

When I’m trying to render multiple lists (2 in my case) after each other, both using <AutoSizer> and <WindowScroller>, the second one does not render properly. It takes up the correct amount of space on the page, but the rows are gone except for a few at the bottom of the page. If you scroll up, a few more of them appears. This issue does not happen after resizing your window, or if you set the width of your <List> component to a static value.

See codesandbox example.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:13
  • Comments:9

github_iconTop GitHub Comments

24reactions
nicolasschabramcommented, Mar 29, 2019

I’ve done some more digging. I’m not familiar at all with the codebase, but maybe my findings still help:

WindowScroller has an updatePosition() method which measures the dom element’s offset and stores it in _positionFromTop and _positionFromLeft. updatePosition() is called in componentDidMount(), but at the time the offsets are stored, the lists themselves haven’t been painted yet. For the first one, that isn’t a problem because _positionFromTop is correct no matter its height. But the second list does depend on what has been rendered above. So what seems to be happening is that an incorrect _positionFromTop is stored during the initial render, breaking virtualization in the second list. Resizing the window triggers updatePosition() to be called again from _onResize(), which fixes the incorrect offsets - hence the behavior demonstrated in my comment above.

Another place where updatePosition() is called is in registerChild. A (rather unsatisfying) quick fix for the problem seems to be doing something like this:

<WindowScroller>
  {({ height, registerChild, scrollTop }) => (
    <div>
      <AutoSizer disableHeight>
        {({ width }) => (
          <div ref={el => registerChild(el)}> // <-- relevant line
            <List
              autoHeight
              height={height}
              rowCount={list1.length}
              rowHeight={32}
              rowRenderer={rowRenderer1}
              scrollTop={scrollTop}
              width={width}
            />
          </div>
        )}
      </AutoSizer>
    </div>
  )}
</WindowScroller>

Note that it only works when recreating the function passed to ref on every render, i.e. ref={el => registerChild(el)} instead of ref={registerChild}. I’ve tweaked @apelsinet’s example accordingly: https://codesandbox.io/s/jjnr1v3r3w?fontsize=14

It’s obviously a hack and probably not the right long-term solution. I’m not sure at all about possible negative implications.

But at least it seems like RV isn’t very far from supporting this use case. 😃

3reactions
nicolasschabramcommented, Mar 28, 2019

@apelsinet, did you make any progress on this? I’m dealing with the same problem right now. I’ve noticed though that it does seem to work after once resizing the window. 🤔

virtualized

Read more comments on GitHub >

github_iconTop Results From Across the Web

ALL browsers fail to render [some] pages correctly: tried
ALL browsers fail to render [some] pages correctly: tried all Windows browsers. There is something odd with my new laptop with NVIDIA ...
Read more >
Width of the Table in AutoSizer and Window Scroller is not ...
I am using React-Virtualized to display a table with a long list of values. So it's a combination of WindowScroller, AutoSizer and Table....
Read more >
Rendering large lists with React Virtualized - LogRocket Blog
So many elements in the DOM can cause two problems: Slow initial rendering; Laggy scrolling. However, if you scroll through the list, you...
Read more >
List Virtualization - Patterns.dev
If you use React and need to display large lists of data efficiently, ... at once (which can cause slower initial rendering or...
Read more >
bvaughn/react-virtualized - Gitter
Hi @bvaughn , on the demo page for ArrowKeyStepper ( this one ) using the arrow ... was not created inside a component's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found