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.

Dynamic rows with children that change size post-render are not re-measured

See original GitHub issue

Ran into an issue with images inside the dynamic rows.

Images are rendered as placeholders first. When the asset is loaded, the image component is re-rendered to correct dimensions. However, as the image component is a child of the virtual row, the row and the virtualizer are unaware of the size change. This causes either a larger-than-intended gap between the elements, or an overlap.

I was able to mitigate it by

  1. Saving the row container node (same that is attached to measureRef) to a separate ref.
  2. Drilling down an onLoad callback prop
  3. Calling measureRef manually with the node saved on step 1 inside onLoad.

It feels a bit cumbersome though. I wonder if this could be resolved inside the library, e.g. by having a resize observer on select nodes. In DIY testing of that idea without touching the library code though I ran into lots of re-rendering that decimated the performance. I understand that maybe there is no good one-size-fits-all solution for this. In this case, maybe we could at least improve the ergonomics of re-measuring individual rows somehow.

Or maybe there is a way to handle this case already and I’m just unaware of it. keyExtractor doesn’t seem to be the solution here because nothing about the row itself changes.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:6

github_iconTop GitHub Comments

1reaction
tannerlinsleycommented, Jun 3, 2022

This seems like it should be solveable in v3 beta by calling virtualizer.measure() when you know your rendered items change in size. There are a lot of ways to detect that size change, so I don’t think we’re going to ship a way to do it automatically.

0reactions
piecykcommented, Feb 18, 2022

I think this should be next step, it’s pretty common use case to have dynamic changes of item dimensions. Current we are in kinda of limbo with 3.0, api changes etc, but after it’s done we will focus on this.

Also if we would allow to pass as prop measuredCache: Record<Key, number>> to useVirtual, that would allow writing simple code for observing rows. Most problematic part is, when someone jumps in middle of list and start to scroll backward, then we need to update scroll position ( that implies we need to know current offset etc) otherwise list will jump a bit 🤔

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resizing rows in dynamic list · Issue #28 · TanStack/virtual
My rows can expand/collapse on click (i.e. change height), but the virtualized list doesn't adapt the item positions. Could this benefit from a...
Read more >
css - How can I dynamically resize child elements equally to ...
I have a fixed-size container which will have items added and removed to it, so i'd like the items to resize to be...
Read more >
How do you dynamically make individual Grid rows size ...
My question is, how do I change this behavior so each row takes on the height of that rows children, NOT the height...
Read more >
A dynamic systems analysis of parent-child changes ...
A dynamic systems analysis of parent-child changes associated with successful "real-world" interventions for aggressive children. J Abnorm Child Psychol.
Read more >
Vue Data Grid: Grid Size - AG Grid
As you set different numbers of rows into the grid, the grid will resize it's height to just fit the rows. As the...
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