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

Commit 6c18a10

Browse files
Haroenveunjae-lee
andauthored
feat(ssr): forward propsData to recreated component (#865)
* feat(ssr): forward propsData to recreated component TODO: this throws a warning (but works) because of: https://github.com/vuejs/vue/blob/7912f75c5eb09e0aef3e4bfd8a3bb78cad7540d7/src/core/util/options.js#L34-L44 I'm not fully sure how to do `new Vue` or pass this parameter correctly. If I `Object.assign` it for `app = new Vue({...extended, propsData})`, it also doesn't work :/ * fix co-authored-by: Eunjae Lee <[email protected]> Co-authored-by: Eunjae Lee <[email protected]>
1 parent aeea263 commit 6c18a10

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

src/util/__tests__/createServerRootMixin.test.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,57 @@ Array [
311311

312312
await renderToString(wrapper);
313313
});
314+
315+
it('forwards props', async () => {
316+
const searchClient = createFakeClient();
317+
318+
// there are two renders of App, each with an assertion
319+
expect.assertions(2);
320+
321+
const someProp = { data: Math.random() };
322+
323+
const App = Vue.component('App', {
324+
mixins: [
325+
forceIsServerMixin,
326+
createServerRootMixin({
327+
searchClient,
328+
indexName: 'hello',
329+
}),
330+
],
331+
props: {
332+
someProp: {
333+
required: true,
334+
type: Object,
335+
validator(value) {
336+
expect(value).toBe(someProp);
337+
return value === someProp;
338+
},
339+
},
340+
},
341+
render(h) {
342+
return h(InstantSearchSsr, {}, [
343+
h(Configure, {
344+
attrs: {
345+
hitsPerPage: 100,
346+
},
347+
}),
348+
h(SearchBox),
349+
]);
350+
},
351+
serverPrefetch() {
352+
return this.instantsearch.findResultsState(this);
353+
},
354+
});
355+
356+
const wrapper = new Vue({
357+
mixins: [forceIsServerMixin],
358+
render(h) {
359+
return h(App, { props: { someProp } });
360+
},
361+
});
362+
363+
await renderToString(wrapper);
364+
});
314365
});
315366

316367
describe('hydrate', () => {

src/util/createServerRootMixin.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,15 @@ function augmentInstantSearch(instantSearchOptions, searchClient, indexName) {
7878
store: componentInstance.$store,
7979
};
8080

81-
const extended = componentInstance.$vnode
81+
const Extended = componentInstance.$vnode
8282
? componentInstance.$vnode.componentOptions.Ctor.extend(options)
83-
: Object.assign({}, componentInstance.$options, options);
83+
: Vue.component(
84+
Object.assign({}, componentInstance.$options, options)
85+
);
8486

85-
app = new Vue(extended);
87+
app = new Extended({
88+
propsData: componentInstance.$options.propsData,
89+
});
8690

8791
app.$options.serverPrefetch = [];
8892

0 commit comments

Comments
 (0)