jaredLunde / masonic

🧱 High-performance masonry layouts for React
https://codesandbox.io/s/0oyxozv75v
MIT License
796 stars 49 forks source link

CPU max out when using useInfiniteLoader with totalItems arguement #162

Open justisom opened 6 months ago

justisom commented 6 months ago

I want to first say thank you for your patience with my many questions over the past few days. I truly appreciate your help and this module has proven to be a one stop shop for a lot of features I wish to implement. THANK YOU!

While trying to implement infinite scrolling I noticed a quirk with totalItems argument in useInfiniteLoader that causes the CPU to spike over 100% when scrolling beyond the item limit.

To Reproduce I forked the example code and put a print statement in the fakeQuery function. Once I hit the max it starts printing out like crazy and the CPU spikes.

I added totalItems: 100 at line 20 and a print statement at line 129.

Expected behavior I figured the function call for queries would stop after the limit had been hit.

jaredLunde commented 6 months ago

Hmm yeah that does look like there is potentially a bug somewhere in here: https://github.com/jaredLunde/masonic/blob/main/src/use-infinite-loader.ts#L31-L38