Conversation
|
This pull request is automatically deployed with Now. Latest deployment for this branch: https://venia-git-bug-double-loaded-category-images.magento-research1.now.sh |
| Math.floor( | ||
| ~~getQueryParameterValue({ | ||
| location, | ||
| queryParameter: 'page' |
There was a problem hiding this comment.
One thing that stands out to me in all of this is that I don't know who the page parameter "belongs" to anymore. We need to read it to get the initialPage value for the usePagination hook we initialize here in category.js, but the only place in which we update the query parameter is within pagination.js, a child component.
There was a problem hiding this comment.
That's a really good observation, related to the question in #1305. I think we need to encapsulate the query parameter handling entirely inside usePagination; it should use useSearchParam under the hood.
There was a problem hiding this comment.
I made these changes. I'll wait for feedback before fixing the tests.
|
zetlen
left a comment
There was a problem hiding this comment.
Excellent change, good debugging, a couple small things. That page URL parameter definitely needs to be abstracted into the hook itself.
| Math.floor( | ||
| ~~getQueryParameterValue({ | ||
| location, | ||
| queryParameter: 'page' |
There was a problem hiding this comment.
That's a really good observation, related to the question in #1305. I think we need to encapsulate the query parameter handling entirely inside usePagination; it should use useSearchParam under the hood.
|
@sirugh QA pass, good to merge if review is approved. |
a7bea0c to
ffddff4
Compare
…etter. Also added error handling to useQuery to throw an error if apolloClient throws. Also fixed default page size in gallery items. Also removed some unnecessary cleanup from pagination component and moved it to the category page.
…component to usePagination hook
ffddff4 to
2222cf2
Compare
…agination hook to only prefix with _ if namespace is provided
| initialPage, | ||
| initialTotalPages = 1 | ||
| } = {}) => { | ||
| const searchParam = namespace ? `${namespace}_${parameter}` : parameter; |
There was a problem hiding this comment.
This only includes an _ if namespace is provided. It was incorrectly using a param of _page.
Description
Pagination had some bugs that caused a double fetch. Specifically the
usePaginationhook initialized with a current page of0, which is just wrong -- it should default to 1, if anything. So I updated the hook to accept aninitialPageparam which if omitted will default to 1. Now, when we first load, we check thepagequery param and use it if defined.I ran into another issue, which is that the apollo client will actually just throw the GQL errors, and we never caught them. So, for example, if you request
page=5and there are only 4 pages, ApolloClient throws an error and we just break. To fix this I added a try-catch and then some retry logic to the category page.Additional "bonus" fixes:
Related Issue
Closes #1297.
Verification Steps
page=65and press enter. It should update topage=1and it should only fetch one set of images.Screenshots / Screen Captures (if appropriate)
Proposed Labels for Change Type/Package
usePaginationnow defaults to1instead of0so this is technically a breaking change.Checklist: