Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support promise for renderToString in vue-server-renderer #6160

Closed
maunier opened this issue Jul 19, 2017 · 2 comments
Closed

Support promise for renderToString in vue-server-renderer #6160

maunier opened this issue Jul 19, 2017 · 2 comments

Comments

@maunier
Copy link

maunier commented Jul 19, 2017

What problem does this feature solve?

Because now the render.renderToString function return nothing, but its a async function, i need return response in its callback, it will lead to bug in koa. I have to wrap it to a function return promise to let it to work. Something like this:

function render(renderer) {
    let resolve;
    const promise = new Promise(r => resolve = r);

    renderer.renderToString(context, (err, html) => {
      resolve(html);
    });

    return promise;
}

server.get('*', async ctx => {
    const res = await render(renderer);
    ctx.status = 200;
    ctx.body = res;
})

Maybe the render.renderToString return a promise will be better ?

What does the proposed API look like?

koa2:

server.get('*', async ctx => {
    const res = await renderer.renderToString(context);
    ctx.status = 200;
    ctx.body = res;
})
@JounQin
Copy link
Contributor

JounQin commented Jul 19, 2017

Maybe you can use util.promisify.

@nickmessing
Copy link
Member

I do like that, considering we have somehow similar API with Vue.nextTick where you can pass callback or you get a promise.

@nickmessing nickmessing changed the title vue-server-render not support koa perfectly Support promise for renderToString in vue-server-renderer Jul 19, 2017
ztlevi pushed a commit to ztlevi/vue that referenced this issue Feb 14, 2018
f2009 pushed a commit to f2009/vue that referenced this issue Jan 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants