-
Notifications
You must be signed in to change notification settings - Fork 157
SSR is broken #1054
Comments
This should be the fixed version: https://codesandbox.io/s/crimson-bush-ni2ii?file=/src/main.js. Not sure at which point Vue made the component name required, but before function renderToString(app) {
import('vue-server-renderer/basic').then(({ default: _renderToString }) => {
return new Promise((resolve, reject) => {
_renderToString(app, (err, res) => {
if (err) reject(err);
resolve(res);
});
});
});
}
function cloneComponent(componentInstance, { mixins = [] } = {}) {
const options = {
serverPrefetch: undefined,
fetch: undefined,
_base: undefined,
name: 'ais-ssr-root-component',
};
let app;
// copy over global Vue APIs
options.router = componentInstance.$router;
options.store = componentInstance.$store;
const Extended = componentInstance.$vnode
? componentInstance.$vnode.componentOptions.Ctor.extend(options)
: // this different, in the source code is only `Vue.component(Object.assign({}, componentInstance.$options, options))`
Vue.component(
options.name,
Object.assign({}, componentInstance.$options, options)
);
app = new Extended({
propsData: componentInstance.$options.propsData,
mixins: [...mixins],
});
// https://stackoverflow.com/a/48195006/3185307
app.$slots = componentInstance.$slots;
app.$root = componentInstance.$root;
app.$options.serverPrefetch = [];
return app;
}
// ...
mixins: [
createServerRootMixin({
$cloneComponent: cloneComponent,
indexName: 'instant_search',
searchClient,
// ...
serverPrefetch() {
return this.instantsearch.findResultsState({
component: this,
renderToString,
});
}, |
If you want an inbetween solution while we figure out what went wrong, you can also use Vue InstantSearch v3 |
fixes #1054 Essentially the problem is that $vnode is usually available, but not when the this is a root Vue instance. In that case we are in the "Vue.component" case, which before now always was wrong (it takes two arguments, not one)
* fix(ssr): extend component correctly if at root (vue2) fixes #1054 Essentially the problem is that $vnode is usually available, but not when the this is a root Vue instance. In that case we are in the "Vue.component" case, which before now always was wrong (it takes two arguments, not one) * not only * Update src/util/__tests__/createServerRootMixin.test.js Co-authored-by: Sarah Dayan <5370675+sarahdayan@users.noreply.github.com> Co-authored-by: Sarah Dayan <5370675+sarahdayan@users.noreply.github.com>
* fix(server): extend component correctly if at root Essentially the problem is that $vnode is usually available, but not when the this is a root Vue instance. In that case we are in the "Vue.component" case, which before now always was wrong (it takes two arguments, not one) Same as #1104 see also #1054 * Update src/util/createServerRootMixin.js * make the funky new test pass * update test name, as in #1104 * Update src/util/__tests__/createServerRootMixin.test.js Co-authored-by: Sarah Dayan <5370675+sarahdayan@users.noreply.github.com> Co-authored-by: Sarah Dayan <5370675+sarahdayan@users.noreply.github.com>
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. |
…nstantsearch#1104) * fix(ssr): extend component correctly if at root (vue2) fixes algolia/vue-instantsearch#1054 Essentially the problem is that $vnode is usually available, but not when the this is a root Vue instance. In that case we are in the "Vue.component" case, which before now always was wrong (it takes two arguments, not one) * not only * Update src/util/__tests__/createServerRootMixin.test.js Co-authored-by: Sarah Dayan <5370675+sarahdayan@users.noreply.github.com> Co-authored-by: Sarah Dayan <5370675+sarahdayan@users.noreply.github.com>
Bug 🐞
What is the current behavior?
The SSR example causes an error, which I'm also receiving in my own implementation.
Make a sandbox with the current behavior
https://github.com/algolia/vue-instantsearch/tree/master/examples/ssr
The only things I changed, are:
What is the expected behavior?
Not receiving that error
Does this happen only in specific situations?
No
What is the proposed solution?
Seems like the code which errors is trying to use the
this
passed infindResultsState
as a constructor. I don't understand the context, so that's as far as I got :-)What is the version you are using?
4.0.0
The text was updated successfully, but these errors were encountered: