-
Notifications
You must be signed in to change notification settings - Fork 113
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
[Woo POS] Stop GhostableCardView
rendering, and network requests when there are no new items
#14382
base: trunk
Are you sure you want to change the base?
[Woo POS] Stop GhostableCardView
rendering, and network requests when there are no new items
#14382
Conversation
📲 You can test the changes from this Pull Request in WooCommerce iOS by scanning the QR code below to install the corresponding build.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is the right approach – it still results in unlimited network requests, and can get the isLastPage
decision wrong.
We will keep our views and logic easier to understand and change if we avoid adding flags like isLastPage
, or at least avoid using them in views – the itemListState can give everything we need here. It should be either loaded
or loading
, depending on whether we want to show the ghost cell or not.
If we don't want to show it, but still do a network request, we can just leave it as loaded
while that request continues.
I've done some exploration of it and it would work better if we determine whether we're at the end of the list in the service layer, since there it can throw a pageOutOfRange
error if we get no products back in the API response. That avoids the client-side filtering having an effect.
We may still need some private state in the aggregate model, but it doesn't need to be published or even available to the view. It should just inform what we publish in the itemListState
property.
Give me a shout if you want to pair on it tomorrow, especially if any of this isn't clear. I've got my exploration on a branch but it's messy and I want to focus on the cart and other fixes today, rather than polishing it.
@@ -134,15 +134,15 @@ private extension ItemListView { | |||
}) | |||
} | |||
GhostItemCardView() | |||
.renderedIf(posModel.itemListState.isLoadingAfterInitialLoad) | |||
.renderedIf(posModel.itemListState.isLoadingAfterInitialLoad && !posModel.isLastPage) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems a bit off...
Why do we need to check what page it's loading if the state is a loading state?
The itemListState
shouldn't be any kind of loading if there's nothing left to load; it should just go directly to loaded
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True that, the isLastPage
property shouldn't influence here, and leave the View to just render when state is loading, shouldn't have to know about anything else.
if uniqueNewItems.count == 0 { | ||
isLastPage = true | ||
} else { | ||
isLastPage = false | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should lobby for X-WP-Total
and X-WP-TotalPages
headers to be passed through the JP tunnel, instead of trying to figure this out for ourselves.
…w-when-last-page # Conflicts: # WooCommerce/Classes/POS/Presentation/ItemListView.swift
isLastPage
when there are no new itemsGhostableCardView
rendering, and network requests when there are no new items
If there are no eligible products at all (page = 1 && products = 0), we would throw the out of range error, rather than returning empty.
…w-when-last-page # Conflicts: # WooCommerce/Classes/POS/Models/PointOfSaleAggregateModel.swift # WooCommerce/WooCommerceTests/POS/Models/PointOfSaleAggregateModelTests.swift
Behavior is the same, but some tests that expect `.empty` state fail with `.loaded([])` instead. Effectively these mean the same but let’s defer it outside of the scope of this PR.
Thanks for the review and the pairing @joshheald , this is ready for review when you have the chance. No logic has been changed since yesterday except for this commit, which checks we're not throwing the out of range error if we just happen to have no eligible products at all. Screen.Recording.2024-11-14.at.10.58.11.movWhen cleaning up the |
We don’t do anything specific with this error in the case that the page is out of range, but we still use the same associated type when there’s an error on loading further products.
Description
This PR makes the GhostableCardView to only rely on
isLoading
state in order to render, as well as marking the last page when no new unique items are fetched from the remote. This resolves two issues:GhostableCardView
will no longer render indefinitely when we reach the end of the item listisLastPage
resets.Caveat: I think there’s a compromise to be made with our current limitations on eligible products: if there’s a gap in the API response between eligible products we might trigger the “last page” too early (this is easily reproducible if we limit products per page to something like 5, and then there's 5+ non-eligible products in the request).We can see this in the video below where the GhostableCardView doesn't render for a second if there's a gap, but then we immediately fetch next page, it has items, so loads the rest normally. This should not be a problem in release, as would imply that the merchant has a 100+ product gap that are not eligible between page fetches. This can be improved in the future as needed, but any advice or recommendation of how to handle it better is welcome.Update: these have been resolved in the latest iteration
Screen.Recording.2024-11-12.at.13.48.32.mov
Steps to reproduce
POSConstants.productsPerPage
to something like 5 or 10, and load POSGhostableCardView
will also stop as soon as the end of the page is triggered ( you can create a new jurassic ninja site with 1 simple product, or I can send access to a test site if needed 👍 )RELEASE-NOTES.txt
if necessary.Reviewer (or Author, in the case of optional code reviews):
Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement: