-
Notifications
You must be signed in to change notification settings - Fork 157
Component perform same request on creation #365
Comments
I really think issues like those should be solved upstream. I don't understand why the cache doesn't kick in for these requests, and neither in RIS 😢 |
I agree on the fact that maybe the cache could handle this. But we still have a problem we shouldn't perform four request on component creation. If it's a design problem we should probably think about it at some point. Same for RIS. |
I can take a look at this. However it seems there are 4 times the amount of queries. In Vue InstantSearch, the solution for this kind of problems is to "stop" the store and "start" it again. In stories I voluntarily didn't use that to not introduce complexity. |
Yes, but inside the component we already do something with "start" & "stop". We also need to do it at the application level?
On Storybook it should be the latest version right? |
This is done by default in the Index component. In story book however it is a bit hacky and the logic doesn't kick in.
On the live version on don't see the 4 requests issue, do you? Edit: I see it on first load indeed. Probably related to Storybook and the way it loads / mounts stuff. |
Thanks for the precisions @rayrutjes! But on Spencer & Williams if you trigger a search on the Homepage, it will trigger two requests with two duplicates (four in total). |
I'm not sure this library is used everywhere on that project. |
We should upgrade to the latest version before saying anything definitive - @utay do you mind doing this and testing it out again? |
Sure. I'll upgrade, test it and let you know! |
So upgrading the library (to |
The However, the helper is not always able to detect if something has really changed, so it will emit a change event and trigger an Algolia call. I would need to investigate the implementation in more detail to come up with a better idea on how to address / improve this. |
@utay could you point me toward the files you are referring to? |
I spent a fair amount of time on this and narrowed down the issue to a few things.
The current issue is that even though the query parameters are the same, they are not detected as such by the helper. |
I think I will need to summon @bobylito here. |
Hello everybody 👋 Happy to provide some information about the "change detection". The helper is composed of two layers:
This mechanism is the core to the emission of "change" events. When the reference to the current search parameters is the same as the new one, the helper doesn't trigger a change event. A "false positive" change event might happen if the SearchParameters returns a new instance even though it's not supposed to. |
Thanks for that explanation @bobylito , I feel like this helps already narrowing down the issue.
I think this is what is happening, but I will need to spend a bit more time on it to figure out why the helper chooses not to return the previous state instance. I've already found part of the issue which is that the parameters are sometimes observed by Vue, which means some additional keys are part of the value meaning that the helper will consider it as a new value. I will keep you posted. |
Hi @rayrutjes, not sure if it can be of any help but I met some similar behavior of storybook on my side, Adding a withDecorator, calls the story.add callback twice. And adding custom editable values to withKnobs duplicates the mounting process thus duplicates the http calls. Maybe the withPreview you are using doubles it. For the quadriple http calls issue, it may be related to the 'computed get/set' behavior in the input component which can call 'set' multiple times even if its the same value(on init, on new default value). Moving the set(value) searchStore calls to a query watcher can solve the problem. Good luck! ✌️ |
please ope n a new issue with reproductible example if this problem is happening for anyone else 👍 thanks everyone for the information given here 🙂 |
In Storybook all components perform at least two requests when they are created. When a component involved some facets (ex: RefinementList, RangeInput) the component will trigger four requests on creation.
You can reproduce easily in Storybook, open the developer panel & watch the network panel. Maybe it's related to how Storybook instantiate the page, but I also checked on Spencer & Williams and some of the requests are also executed multiple times. On the homepage when you trigger a search two requests are trigger and they are both replay once (four request in total).
The text was updated successfully, but these errors were encountered: