-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
recomputeRowHeights is not always re-rendering #307
Comments
Hey @chiss2906, I'll need you to provide a Plunker that demonstrates what you're seeing. I'm fairly confident that the issue here lies somewhere in your props/state tracking and not in |
@bvaughn Here is the link to the Plunker: https://plnkr.co/edit/o4ArW2Os4XDdlTV8OuRx?p=preview :) |
When resize is requested, your Here's a fixed version: The key basically boiled down to checking to see if any heights had been recomputed before the ref was set, and letting |
@bvaughn I believe this is not the whole story: https://plnkr.co/edit/fy1GmIbjs255ZqAPi6ew?p=preview I added something that blinks every few seconds, and if you enable the alternatel height detector, it will adjust. However, I noticed that if there are a number of recalculation requests coming in before VirtualScroll gets to it, it will handle the last one and not all the ones requested. I think the callback should keep track of the lowest index requested. |
This doesn't sound correct to me, but maybe I'm misunderstanding you. This means if you called |
This seems to be what I'm seeing, looking at your demo too. Looks like rows are being expanded and shrunk as "blink" is added and removed. |
Ah, I think I understand. And I think this is just how your test harness is setup. Each |
I think in my desire to make the blinking remeasuring work, I muddled my point. I made the plunker more obvious. The problem is that, if you keep the regular row height detector (which can't detect when its sub-children change height and therefore won't call recalc a lot), you can quickly scroll down to some location, and then there will be cells that do not have the correct height. Slow scrolling works fine. the console log for that section is:
So as you can see, a recompute is requested for 24, but it doesn't trigger a request for the new height. |
Sorry @wmertens but I'm not sure I understand. If you scroll quickly, you see some temporary overlap- but this is due to the way the test harness is written from what I can see.
Am I misunderstanding or missing something?
Not sure about this one. My guess would be that row 24 is no longer visible which is why react-virtualized only calculates 25+. This would seem to be backed up by the errors I sometimes see in the console:
You can trace the flow of code (I pasted it above) for resetting a row's height. It's pretty straight forward I think. This is also an area I have automated test coverage on (eg here and here). |
The temporary overlap is not temporary, the screenshot is what it looks like when I stop scrolling. (using react-measure and react-height, the other one forces recalcs all the time) Here's how I can always reproduce it: scroll quickly to the end and then scroll back up at normal speed. You will see some overlapping cells that are not the correct height. I noticed the setState errors too, weird because I do clear the interval handler before unmount… All in all, it seems like the problem is incorrect height caching, it may be better if you always call |
the tests don't seem to cover the case where the cell is no longer visible by the time the measurement needs to be done… |
Ah! Scrolling backwards after skipping... resetCell (index: number): void {
this._lastMeasuredIndex = index - 1
} This is the problem. I was not anticipating frequent calls to |
Thanks for sticking with it @wmertens :) 7.12.1 should fix this edge case. I'm still not able to repro what you describe in the test harness, but maybe you can bump the react-virtualized version and verify the fix? |
🎉 7.12.1 fixes it 👍 I wonder if dynamic rows with VirtualScroll + react-height is not a common enough need that it should be part of react-virtualized? In my very un-scientific eyeballing, it seems to be faster than react-measure, and tiny. So when you pass e.g. |
BTW, I was using Chrome 51 on OS X for the repro, and you? Just curious… |
Same, Chrome 51 on OS X El Capitan.
How's react-height different from |
Hmmm, the docs for CellMeasurer say not to use it for VirtualScroll, and the ones for react-height don't mention VirtualScroll :) Actually, I find its API a bit confusing… |
CellMeasurer's interface was written for Grid; that's why the docs say
that. But since VirtualScroll and FlexTable are really just Grids, you
definitely can use it with them. You would just need to adapt the
parameters to match the expected format.
Sorry you find the interface confusing. I think the docs are pretty
straight forward but feel free to suggest improvements.
|
Well, for me the ideal API would be So what I find confusing about the API, I didn't use it before so I'll just call it as I see it:
So the way I understand it now is that CellMeasurer alters Grid somehow, and I would expect that to work more like Redux's Mind you, you did an excellent job on this library, I'm just confused… |
Sorry @wmertens. Didn't mean to ignore. Traveling in Japan at the moment and have spotty Internet access. :) I understand your confusion. Let me try to address the things you mentioned briefly.
|
recomputeRowHeights()
is not re-rendering some of the VirtualScroll cells properly, even though the function passed torowHeight
is receiving a proper value and I callrecomputeRowHeights(index)
when the height changes.Mostly it happens to cells which contains an image, which means their height changes. Less often it happens to rows without it. So basically I would say not all rows that need re-rendering are re-rendered.
Also, sometimes the cell gets re-rendered, but the height does not get updated. I know this because I show the height in the cell and it doesn't match the actual height.
I'm storing the row height in a
heights
object, which has been filled withid: height
pairs from dimensions received byreact-measure
component. The rowHeight gets returned from that.I tried adding a prop to VirtualScroll that counts the number of height updates, and thus is different every time, but that does not help either.
The text was updated successfully, but these errors were encountered: