Replies: 3 comments 2 replies
-
One way in which I found this problematic recently is dynamicWidgets. To have them play nicely with routing, I needed to make sure that all possible widgets are initially mounted, so the search parameters are used for the initial search. I was trying to find a way in which there's a |
Beta Was this translation helpful? Give feedback.
-
The UI state being in control of the whole search parameters is definitely flawed, and I think that the very initial problem comes even before this design decision, which is that widgets are in control of (From the library creation, widgets have been in control of both The more I work on custom search implementations directly based on the JS helper, the more I appreciate non-reactive facet declarations because it leads to more predictable behaviors, and more control as a developer. Ultimately widgets should give hints to the InstantSearch manager that they require certain This shift would let users have better control over the facets. |
Beta Was this translation helpful? Give feedback.
-
#2917 lists a similar issue, as current refinements are based on the helper, it means ui state that's not related to the helper will not show up or have any effect. We could change that by using getUiState in the current refinements widget, and setUiState as its refine, although that obviously is a big breaking change. It also means we'll need to map from the object-form to (nested?) arrays for the actual "refinements". Maybe each widget should be able to map its own ui state to an "refinements" array instead (à la metadata in React InstantSearch) |
Beta Was this translation helpful? Give feedback.
-
There's two problems to this:
This causes ui state to be possibly out of sync after a refine, which is why getUiState needs to
refreshUiState
first.https://github.com/algolia/instantsearch.js/blob/57c32c0a43bd2c6cbdd3f8ea7eac8109e3024f2a/src/lib/InstantSearch.ts#L569-L575
https://github.com/algolia/instantsearch.js/blob/57c32c0a43bd2c6cbdd3f8ea7eac8109e3024f2a/src/lib/InstantSearch.ts#L603-L620
https://github.com/algolia/instantsearch.js/blob/8f2aad2f0465cc883681143f350a11c24ce694e2/src/middlewares/createRouterMiddleware.ts#L26-L38
https://github.com/algolia/instantsearch.js/blob/ddf60adea7cf35f93338d6a70466ccfdbb71749e/src/widgets/index/index.ts#L434-L439
This means that an unmounted widget is automatically no longer in UI State (probably good, its refinement definitely should not be taken in account), but it also means that the following situations aren't possible:
In React InstantSearch we have a slightly different design, where the searchState for a non-mounted widget stays in place, but in the cleanUp phase, widgets remove their respective state. This is logical for a "widgets drive state" design, that we still have, but it means that if you only want to visually unmount a widget (even if another widget is present for the same state), it's not possible.
There's some ways I imagine around this:
Possible solutions
This is a massive breaking change of course for all custom widgets, so maybe a transition period or a good guide on how to transform is needed. It has the advantage of not needing the helper anymore for toggling state (you'd only use getWidgetSearchParameters).
A way in which this could be mitigated is by creating a different way than normal to do createURL and refine in widgets, leaving the current way working, but warning in some way to use the modern method?
At the moment InstantSearch doesn't know the current UI State, it needs to recompute it. I feel like this is problematic to allow unmounted widgets to stay in the UI State.
Beta Was this translation helpful? Give feedback.
All reactions