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.

[BUG] Items get calculated incorrectly when child of flex parent

See original GitHub issue

Describe the bug This may be a bug, or it may be incorrect usage. I am using Virtuoso inside a Material UI Popover, and placing it inside a flex container so it takes up the remaining portion of the popover after some content (see codesandbox link). My understanding is I should be able to have a structure like this:

<div style={{
   display: 'flex',
   flexDirection: 'column',
   height: '100%'
  }}
>
  <div> {'some content of unknown or variable height'}</div>
  <div style={{flex: 1}}>
      <Virtuoso height={'100%'} .../>
  </div>
</div>

And it seems this works just fine when this is just in the regular DOM, as shown in the codesandbox here. But when I put it in a Popover with this same sort of structure, it doesn’t seem to be able to calculate the right number of items to show, and you’ll notice when scrolling to the bottom of the list there’s a gap and not all of them render.

Reproduction https://codesandbox.io/s/vigilant-rgb-xugwm?file=/src/components/App.js

To Reproduce Steps to reproduce the behavior:

  1. Go to the codesandbox
  2. Click the Expand button
  3. Scroll the list down

Expected behavior Should render all items with no gap at the bottom

Desktop (please complete the following information):

  • OS: [e.g. iOS] - macOS Big Sur
  • Browser [e.g. chrome, safari] - Chrome

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
genepaulcommented, Jan 7, 2022

@petyosi, I determined what the issue is. It appears to be due to the fact that the Material UI Popover animates a transition when it enters. The Virtuoso tries to grab dimensions while the Popover is transitioning and gets incorrect information. If I defer the rendering of the Virtuoso until the Popover has fully entered, the Virtuoso works correctly. So this is not an issue with Virtuoso. I just wanted to add the update here for anyone else who happens upon this issue and wonders what the problem was. If I come up with working code I’ll try to update with a codesandbox. I did a really dirty hack in my testing where I just did a setTimeout in a useEffect and that proved the issue. I think there’s probably a better way to do it though. Thanks for creating such an awesome library!

0reactions
genepaulcommented, Dec 9, 2021

I’m fairly certain it’s padding. I tried to clear margins.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Flexbox: wrong width calculation when flex-direction: column ...
The problem is that the browser still calculates the container's width as a sum of inner items' widths! My container block should have...
Read more >
Incorrect free space calculation with flex items in IE 11 #128
The bug appears when you have extra size comparing to flex-basis , i.e. you has flex growing. When you set width: 45% you...
Read more >
Flex container width and height incorrectly calculated for `flex ...
It's size is being incorrectly calculated. What is the expected result? The <il> children should be contained no matter how they wrap and...
Read more >
`flex-grow` is weird. Or is it? | CSS-Tricks
First we set the display property of our parent element to flex and by doing that our child elements become flex items and...
Read more >
Normalizing Cross-browser Flexbox Bugs - Philip Walton
In IE 10-11, flex items ignore their parent container's height if it's set via the min-height property. · Chrome, Opera, and Safari fail...
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