-
First of all thank you for the amazing library! We are about to use react-virtuoso for a slack like application with multiple tabs, each having a chat message list (Prepending items + infinite scroll, making use of initialTopMostItem, firstItemIndex...) So far so good, we were able to set up the list, infinite scroll + prepending items works almost perfectly BUT we are completely stuck in preserving the chat scroll position when the user navigates to another chat (using nextjs router and changing the dynamic url path to the new chat_id). Our approaches:
We couldn't get either of the approaches to work and would be really curious about How you guys would achieve this? Our current Virtuoso component looks as follows (if important), using chat.chat_id as the key to differentiate each list:
<Virtuoso
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 6 replies
-
Hey, In case nobody from the audience here helps with your questions, I am happy to help you with your implementation should you choose to sponsor the project. There are several options I am happy with, including a one-time sponsorship. Cheers, |
Beta Was this translation helpful? Give feedback.
-
@Paulo2703 after examining your setup, I can see that there's no reasonable way to implement location persistence with the APIs present in v4.2. The problem is not due to your implementation, or the overscan/increaseViewportBy, but due to the data set changes causing loss of previous measurement data. Your usage of the To address that, I just released v4.3 which has a new API that lets you to get / restore the component internal state - this includes the measured item heights and the scroll position. You can check how it works in this example. Check the Let me know if this works for you. Once I get some confirmation, I want to bring this example to the online documentation. You can also contact me over the email in my github profile. |
Beta Was this translation helpful? Give feedback.
-
@petyosi wow, this is amazing! We now got the state restoration to work completely flawlessly! Thank you so much for your help and the great library. Without having tested this yet, are both functions also available for the grouped list? |
Beta Was this translation helpful? Give feedback.
-
@petyosi Right now we are combining the infinite scroll setup with the discussed restoreStateFrom functionality . The issue here seems that the restoreStateFrom fires again when the list prepends new items and therefore re-sets the state to the saved one. Taking your approach of only saving the state when the actual list completely destroys (I.e. when the channel changes) results in rejumping back to that state when the list prepends. This state is then of course not anymore up to date. We tried to continuously update the cached state by shooting the new state into the cache using the onScroll method (also see previous link) but this also has some issues, as it still causes some jiggle when prepending the list. Does this make sense and/or do you have another idea how to overcome this? |
Beta Was this translation helpful? Give feedback.
-
@Paulo2703 While this sounds like a kind of bug I am prone to, I failed to re-create it in the example. I will need your further input to resolve the problem for you. Please bear with me. Here's an updated version of the sandbox from above. It includes pre-pending items with the How I test - I scroll a channel until older messages are prepended. Then I switch to another channel. Then I switch to the previous channel, scroll up until more are prepended, then toggle once more. It seems to be working for me. Is there something that I am missing in the way I test? Or, perhaps, your setup is a bit different than the example? Can you fork the sandbox and change it so that the problem is reproducible there? We should be able to figure it out from here. To address the details you've shared - the whole setup should not be so complicated. State should be cached once (upon component destruction) and restored once (when the component is mounted). |
Beta Was this translation helpful? Give feedback.
@Paulo2703 after examining your setup, I can see that there's no reasonable way to implement location persistence with the APIs present in v4.2. The problem is not due to your implementation, or the overscan/increaseViewportBy, but due to the data set changes causing loss of previous measurement data. Your usage of the
key
attribute is correct, as technically, you're rendering a new list.To address that, I just released v4.3 which has a new API that lets you to get / restore the component internal state - this includes the measured item heights and the scroll position. You can check how it works in this example. Check the
getState
ref method and therestoreStateFrom
attribute.Let me kno…