Skip to content
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

Fix #6639: VirtualScroller improve useUpdate comparison #6643

Merged
merged 1 commit into from
May 21, 2024

Conversation

melloware
Copy link
Member

Fix #6639: VirtualScroller compare using deepEquals

@melloware melloware added the Core Team Issue or pull request has been *opened* by a member of Core Team label May 20, 2024
Copy link

vercel bot commented May 20, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
primereact ⬜️ Ignored (Inspect) Visit Preview May 20, 2024 9:47pm
primereact-v9 ⬜️ Ignored (Inspect) Visit Preview May 20, 2024 9:47pm

@mamsellem
Copy link

mamsellem commented May 20, 2024

(copied from comment on the ticket #6639).

I don't think using deepequals is a good idea.
We are only interesteed in updating the bounds of the virtual scroller, so only the dimensions of the items matter, not the items themselves.

This was my fix for this issue:

line 570 of VirtualScroll.js

useUpdateEffect(() => { 
   if (!prevProps.items || prevProps.items.length !== (props.items || []).length
     || (both && prevProps.items[0].length !== (props.items ? props.items[0].length : 0))) {
      init();
 } 

What do you think ?

@melloware
Copy link
Member Author

Yes but your fix presupposes item[0] is an array of things etc. To me that seems riskier than a deep equals where IF the collection changes at all it must re-render?

@mamsellem
Copy link

My understanding is that when virtualScroller "both" property is set to true, then items should be an array of arrays, of the same length, so items[0] must be an array.

There is another occurence of items[0] at line 250 of virtualScroller.js:

 const getLast = (last = 0, isCols) => {
            return props.items ? Math.min(isCols ? (props.columns || props.items[0])?.length || 0 : (props.items || []).length, last) : 0;
        };

@melloware
Copy link
Member Author

understood let me look deeper

@melloware
Copy link
Member Author

OK updated, I made it a little more readable and understandable for the next person!

@mamsellem
Copy link

Thank you for taking the time to rewrite the code and make it more readable.
A small optimization would be make the calculations only if both is true, but it's really minor.

@melloware melloware changed the title Fix #6639: VirtualScroller compare using deepEquals Fix #6639: VirtualScroller improve useUpdate comparison May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core Team Issue or pull request has been *opened* by a member of Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

VirtualScroller: does not update items if only rows length changes
2 participants