-
Notifications
You must be signed in to change notification settings - Fork 529
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
setIndex should not set page to 0 (and any other method) #5729
Comments
PR or it did not happen 💃 |
I don't agree, while changing the index you can't know in advance how many pages there will be in the next search therefore resetting the page to 0 is a safe bet. If you are sure that there will be a page, let's say because you are using a slave that only changes the ordering of the results, then you are in a specific case. And then you can use :
|
I agree with both arguments given their context but still @maxiloc was trapped by the behavior of setIndex when loading a state from a url, the order you do .setCurrentPage and .setIndex should not matter on the result. If @maxiloc was trapped then I guess other people will be trapped too? So:
There's no API to handle both cases easily so I would just not set the page in setIndex because setIndex on a API level says: "set the index". not "set the index and the page". Switching to page 0 when changing the index is a sweet shortcut but it can be tricky in some situations (page load). We rather let the API consumer figure out that yes if he's implementing a sorting dropdown, he should reset to page 0 before calling search. thoughts? |
Ok I understand better now. Makes sense when using this API. But, there is
|
I understand your point @bobylito but I think there are a lot of other things you can do that will generate a 0 results answer and that are not checked -> like if I add a wrong numeric filter and so on. I would remove that |
In the case of the URL I would still suggest using the setState, because it's less mutations and less functions calls. But if you think that there is magic when we set the current page to 0 when we change the index, we have to have the same behavior in every methods that has the same behavior. Will fix that in the next version, but this will break the code of the users of the current version. |
Why don't we discuss about this issue around a cup of coffee Monday morning?
|
Of course we will :) |
Hello, This workflow call right my page :
But in this order, it's not working :
Maybe it's important to document somewhere when we should call setCurrentPage ? Have a nice day, |
@Nainterceptor Any method that will change the number of pages will reset the current page to avoid inconsistencies. For example, if it was not the case we could stay on page 3 even though there were only 2 pages returned. So in fact, in your example |
@bobylito It make sense, I agree, but it's maybe important to write somewhere in the doc, to prevent bad usages like mine ? |
You are right! :) algolia/algoliasearch-helper-js#274 |
Maybe we could be even more magical and solve this issue by not resetting to page 0 if the page was manually set somewhere before a call to .search. So if at any moment the user specifically says he wants page 1 and calls for .search() then he should be one page 1, no matter the calling order. Documenting it will maybe help people struggling with this issue get an answer at some point. But only after having struggled with it for a good amount of time. If we can fix the issue for good we should do it? |
+1 for me on this one, this currently breaks pagination on all WordPress instant-search instances ;) |
helper does a setPage(0) on almost every method call see https://github.com/algolia/algoliasearch-helper-js/blob/7d9917135d4192bfbba1827fd9fbcfef61b8dd69/src/algoliasearch.helper.js#L645 and https://github.com/algolia/algoliasearch-helper-js/issues/121
Some context given @rayrutjes comment: algolia/algoliasearch-wordpress#305 I know this is not constructive to say "We need to fix this". Still, we just experienced a painful debugging session because of the setPage(0) being done, behind the scenes while when using the helper, one could always think "This is a somehow low level API (no UI), I am in control when I call setQueryParameter()". It's not the case if you forget/do not know what is happening. |
+1, just spent ~1h debugging instantsearch pagination wondering why an out-of-the-box widget wouldn't change pages... only to realize I have some code that changes the helper state for some advanced use case and was resetting the page before Although I understand where it comes from, it's an unexpected side-effect and breaks the principle of least astonishment. (yeah, big words! :)) |
I also got bitten by In my case, I guess I could just fix it by using |
Since we are gonna work on a revamped helper version those feedbacks are important and shows that everytime we do a little bit of magic in low level libraries it's worth considering the impacts it has more precisely. Thanks! |
We need to methods for this indeed ;) |
Spent half an hour again today on this one in Zendesk. /o\ |
Basically, I think the idea here is that it doesn't make sense to reset the page when done before the |
I would say for such a low level library, when modifying a state object, we should never try to be smart on the page being reset to 0. We have now seen that many people were tricked by it. We are gonna work on instantsearch-core in January and will tackle this issue inside it I think. |
Alright this is indeed very not cool what you have to implement @jerskouille :/ Let's move forward. |
Getting bit in my hack inside the |
Wanted to check in to see where this is at and if anyone has a recommended workaround. I'm running into this while try to create an initial query object based off of URL parameters in my app. |
That’s still the case. You need to |
+1. I spent hours figuring out what was happening.
Some clearer warning must be set somewhere about this |
I understand why it was there in the first place (the setPage(0)) but it the snippet bellow will not load page 2. And I think it is not what we want.
The text was updated successfully, but these errors were encountered: