Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

ais-state-results component doesn't work with SSR #1154

Closed
Gef opened this issue Oct 14, 2022 · 6 comments · Fixed by #1156
Closed

ais-state-results component doesn't work with SSR #1154

Gef opened this issue Oct 14, 2022 · 6 comments · Fixed by #1156

Comments

@Gef
Copy link

Gef commented Oct 14, 2022

StateResults.vue relies on listeners which only seem to run clientside. Even if you just inject an empty component with no arguments, the slot placeholder text won't render serverside.

Adding a call to this.renderFn() in the created() hook seems to solve this problem. Not sure if this is the best solution.

@Haroenv
Copy link
Contributor

Haroenv commented Oct 17, 2022

Can you clarify what you use the stateResults for? Is it to conditionally render other widgets? If you have a sandbox or similar that would be useful.

It's right that in created we could send a call to renderFn, although in many cases the state and results won't yet be available (the network request not having happened yet), thus still causing a mismatch between server and client dom.

Looking forward to see what you're exactly trying to create, so we can see what the best way of resolving is

@Gef
Copy link
Author

Gef commented Oct 17, 2022

Hi Haroenv, we have a set of carousels which are conditionally rendered based on number of hits. So if there are no results i.e nbHits is 0 from StateResults for a given keyword then we don't render the carousel.

I don't have a sandbox but this is the basic code in question. overidden-state-results is a copy of the ais-state-results component.

image

@Haroenv
Copy link
Contributor

Haroenv commented Oct 17, 2022

Right, that makes sense, so with this override (calling renderFn in created) you have what you expect, or does it still prevent rendering the hits in initial results?

@Gef
Copy link
Author

Gef commented Oct 17, 2022

The override ensures the state-results component works serverside and clientside. Without that, the state-results component effectively only works clientside.

This may all be by design, but there is nothing in the documentation to state that and it took a fair amount of debugging to work out what the issue was (hydration errors are my nemisis). Hence the ticket. Even if the change isn't something workable in the core component, if others run into the same issue at least there is a workaround!

Haroenv added a commit that referenced this issue Oct 18, 2022
fixes #1154

If there's results already available, we want to render them ASAP, not waiting for a render event, similar to how the error event is listened to "immediate"
@Haroenv
Copy link
Contributor

Haroenv commented Oct 18, 2022

I've created a PR with your suggestion, thanks for bringing it up! #1156

Haroenv added a commit that referenced this issue Oct 18, 2022
…1156)

fixes #1154

If there's results already available, we want to render them ASAP, not waiting for a render event, similar to how the error event is listened to "immediate"
@Gef
Copy link
Author

Gef commented Oct 18, 2022

Perfect, many thanks!

Haroenv added a commit to algolia/instantsearch that referenced this issue Dec 28, 2022
…lgolia/vue-instantsearch#1156)

fixes algolia/vue-instantsearch#1154

If there's results already available, we want to render them ASAP, not waiting for a render event, similar to how the error event is listened to "immediate"
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants