Closed baoti closed 5 years ago
Vue bindings for server like this:
export const renderVue = (name, component) => hypernova({
server() {
return (props) => {
const vm = new component({ propsData: props });
return new Promise((resolve, reject) => {
renderer.renderToString(vm, (err, html) => {
if (err) {
reject(err);
} else {
resolve(serialize(name, html, props));
}
});
});
};
},
}
I'm not sure I understand - are you saying that the vue server renderer does not synchronously produce a string?
@ljharb Yes.
According to the code, getComponent
's return value is already passed into Promise.resolve
.
getComponent
's return value is a function, but renderFn(context.props)
's return value is a Promise.
context.html = renderFn(context.props);
context.html
got a Promise, not a string.
Gotcha; so you'd need https://github.com/airbnb/hypernova/blob/5dbddc4dba65bd9ee2bcbc04fec11713bfa89d57/src/utils/BatchManager.js#L160 changed.
Seems doable/reasonable to me.
@baoti you could use this npm package https://www.npmjs.com/package/hypernova-vue, there's an article about it too https://medium.com/@felipegaiacharly/using-vue-js-with-hypernova-server-ce792dcf1ac7
@marconi1992 Thanks, It works.
I am working on vue bindings for Hypernova, but vue-server-renderer renderer pass html by callback:
So, I'd like
getComponent
support a function which return a Promise, just likeprops => Promise.resole(html)
.