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 viewCache for gridList (resolves issue #32) #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ghenry22
Copy link

@ghenry22 ghenry22 commented Jul 14, 2024

Resolves #32

If you look at the itemsPerRow calculation you can see that for listview it is always 1. For grid view it is a calculation that relies upon clientWidth.

When you navigate from a list to a detail page for example, the virtualscroll element is hidden so clientWidth changes to 0. When you navigate back to your list you get a scroll to a random location and don't benefit from the view cache as the change in itemsPerRow from x to 0 and back to x as the virtualscroll element goes visible -> invisible -> visible again causes a change and invalidates the cache.

Only applies when the private _itemsPerRow is already a value greater than 0.

Have tested in a couple of my own apps and it's working great now when I navigate back from a detail view with gridlist enabled I get the cached view exactly as it was which is perfect! Have not seen any issues or side effects and wouldn't expect to as this only catches the case where clientWidth goes to 0, in which case the old logic would show nothing anyway.

@ghenry22 ghenry22 changed the title fix viewCache for gridList resolves #32 fix viewCache for gridList (resolves issue #32) Jul 14, 2024
let itemsPerRow = gridList ? Math.floor(scrollContainer.clientWidth / itemWidth!) : 1;

// Don't reset items per row to 0 on view change as it invalidates the viewCache
if (itemsPerRow === 0 && this._itemsPerRow > 0) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to safely skip running all of the logic in this subscription when the list element has a width or height of 0. Instead of checking for itemsPerRow being 0 here, we could update the filter condition on line 304 to additionally check that the clientWidth and clientHeight of scrollContainer are both greater than 0.

This should hopefully result in the same fixed behavior and also avoid updating other state variables unnecessarily.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll test it out and see if the behaviour is the same, will update the PR accordingly, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Viewcache does not apply when grid is enabled
2 participants