Optimistic UI #4403
-
InstantSearch has always relied on the MotivationThe current InstantSearch lifecycle relies on the Algoliasearch Helper events—and we rely on the This is why I'd like to introduce the discussion about what is often called "Optimistic UI". DescriptionAn optimistic UI follows the principle of displaying an optimal state when an action can take some time. In the context of InstantSearch, that would be computing the expected UI after an interaction as soon as possible, and to complete this UI after the state is effectively returned by the network. FlowPrerequisitesTo achieve such an experience, I think that giving access to the search status to our APIs (e.g., What it would look likeHere's a implementation from scratch (no Algoliasearch Helper, no InstantSearch) of what I have in mind for this feature. Notice:
Going forwardI believe this is a feature that people don't realize they need, but they won't be able to go back once they have it. Does anybody else realize they want this? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 6 replies
-
I guess what we can decide as indicator for "offline" is an error returned from algoliasearch, is that what you had in mind? |
Beta Was this translation helpful? Give feedback.
-
TIL about SWR and its Local Mutation reminded me of this discussion. |
Beta Was this translation helpful? Give feedback.
-
Since version 4.50.0 of InstantSearch.js, 4.8.0 of Vue InstantSearch and 6.39.0 of React InstantSearch Hooks, we support optimistic rendering as described here.
|
Beta Was this translation helpful? Give feedback.
-
I've implement something like this in React Instant Search Hooks for my custom refinement list component.
The code is roughly: const [selectedValues, setSelectedValues] = useState(() =>
items.filter((item) => item.isRefined).map((item) => item.value)
)
useEffect(() => {
setSelectedValues(items.filter((item) => item.isRefined).map((item) => item.value))
}, [items]) The checkbox uses |
Beta Was this translation helpful? Give feedback.
Since version 4.50.0 of InstantSearch.js, 4.8.0 of Vue InstantSearch and 6.39.0 of React InstantSearch Hooks, we support optimistic rendering as described here.