-
Notifications
You must be signed in to change notification settings - Fork 157
During SSR the url doesn't get read #1062
Comments
Might be that I'm not aware of another way to push the state into vue-instantsearch, the example suggest though that See also the post I created on Discourse: https://discourse.algolia.com/t/how-to-pass-current-url-to-vue-instantsearch-routing-during-ssr/13476 |
I think it's not the url, my ssr is not working either anymore, this sandbox works: this one doesn't: Only change is that nuxt was upgrade to 2.15.8 not sure what deps it broke |
I reused my old yarn.lock and it works again, either some vue package or some instansearch.js package caused this issue. I leave it to the maintainers to figure out which one sh*t the bed |
Those two sandboxes look exactly the same to me, even the nuxt version resolves to 2.15.0 in both, the . Unfortunately I have no idea what's the difference that could be causing the url not to be read. I'm guessing maybe codesandbox doesn't respect the lock file somehow? can you reproduce this working/not working locally too? |
That is highly interesting, so what I did was "yarn upgrade" in the other sandbox, not sure why the yarn.lock didn't update, I ran yarn upgrade again and now the lock file has been updated. And yes I had the exact same issue locally: I then copied an old yarn.lock over and upgrade packages (nuxt etc.) individually, but not vue-instantsearch and the bug didn't occur, so my assumption is that some of the "@algolia" dependencies caused the issue. |
do you have a place with the actual packages that are different (a new lock file or something?) |
For your information, in this discourse topic we were also digging a bit deeper: https://discourse.algolia.com/t/how-to-pass-current-url-to-vue-instantsearch-routing-during-ssr/13476/7 I came there to the conclusion that things break in between |
Between those versions InstantSearch.js (a dependency) has changed a lot of versions, I guess that would be the issue, but not sure yet. Could you pinpoint it to a certain version via a lock file? |
I can narrow it to these versions: Here are the lock files: |
In that case you can try the following things and see if that continues to work for you:
|
@Haroenv I found that from on instantsearch.js 4.29.1 SSR breaks, 4.29.0 still works |
With 'SSR breaks' I mean that the url doesn't get read, and thus every page on the server is rendered without any state And I tested that in combination with |
hmm, seems like it's the same issue as showed up in #1066, sorry that I haven't yet found out exactly why https://github.com/algolia/instantsearch.js/pull/4849/files causes the URL to be read / written as empty (read too early and saved?) |
Here is a sandbox demonstrating the issue: https://codesandbox.io/s/cranky-mountain-2p5pg?file=/package.json After increasing the version of instantsearch.js in the "resolutions" section of package.json:21 to version 4.29.1 the option of the refinementlist doesn't stay selected because SSR renders the page with an empty state (and thus no option selected) |
@Haroenv Great that the issue has been found, I'll stick to 4.29.0 of instantsearch.js for now |
fixes algolia/vue-instantsearch#1066 fixes algolia/vue-instantsearch#1062 see: #4849 In Vue InstantSearch SSR, the mainIndex gets init'ed *before* it does in regular InstantSearch (see https://codesandbox.io/s/beautiful-mestorf-ijc75?file), and at that point the ui state should already be initialized (before start).
We have just finished a comprehensive refresh of the server-side interaction with routing in the case of Vue InstantSearch. This managed to close this issue for both v3 in 3.9.0 and v4 in 4.3.2. The pull requests in question are:
If the component at the root is the one doing findResultsState, it doesn't have access to $vnode, and in that branch the component name is required to be passed via the first argument.
This is a little more involved, but fixes the issue where routing is not taken in account. Essentially in InstantSearch it was changed so that routing only gets read on .start, but Vue InstantSearch was faking start. Luckily, in a recent version of InstantSearch, some functionality of server rendering / initial results has moved inside InstantSearch itself, and it avoids the issue, as we can use regular 'start' from then on. |
@Haroenv Finally got around testing this, the latest version fixes the issue! 🎉 |
Bug 🐞
What is the current behavior?
During SSR the page gets rendered with an empty state because the state doesn't get read from the url.
Make a sandbox with the current behavior
See SSR example, neither
routing.router.read
orrouting.router.onUpdate
gets called.What is the expected behavior?
That vue-instantsearch tries to retrieve the current state from the URL, using the routing.router methods
Does this happen only in specific situations?
No
What is the proposed solution?
That either
routing.router.onUpdate
gets called so that the callback can be used to push the state into vue-instantsearch, or thatrouting.router.read
gets called so that either the state is retrieved automatically.What is the version you are using?
3.3.0 and 4.0.1
The text was updated successfully, but these errors were encountered: