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

renderToStream: first chunk too big cause vue-meta can't get correct meta info of child components #44

Closed
jiangfengming opened this issue Dec 29, 2016 · 2 comments
Labels

Comments

@jiangfengming
Copy link
Contributor

In stream.once('data', ...), if the first chunk is too big, the following child components haven't been created at the moment, so their metaInfo won't have effects.

Github: https://github.com/fenivana/vue-meta-streaming-issue

Run in node.js:

const Vue = require('vue')
const renderer = require('vue-server-renderer').createRenderer()
const VueMeta = require('vue-meta')

Vue.use(VueMeta)

const vm = new Vue({
  metaInfo: {
    title: 'root'
  },

  template: `
    <div>
      ${'a'.repeat(100000)}
      <foo/>
    </div>
  `,

  components: {
    foo: {
      metaInfo: {
        title: 'foo'
      },
      template: '<div>foo</div>'
    }
  }
})

const stream = renderer.renderToStream(vm)

stream.once('data', () => {
  // BUG: title is 'root'. SHOULD be 'foo'
  console.log(vm.$meta().inject().title.text())
})
@atinux atinux added the bug label May 15, 2017
@atinux
Copy link
Member

atinux commented May 15, 2017

Hi @fenivana

Thank you for this bug report, actually the only workaround I found is this one:

const stream = renderer.renderToStream(vm)

let head = ''
let html = ''

stream.on('data', (data) => {
  html += data.toString()
})

stream.on('end', () => {
  head += vm.$meta().inject().title.text()
  console.log(head, html)
})

Sadly it seems more a bug related to vue-server-renderer instead of vue-meta.

In the meantime, you can use renderToString.

@pimlie pimlie added the pending label Mar 8, 2019
@pimlie pimlie removed the pending label Apr 23, 2019
@pimlie
Copy link
Collaborator

pimlie commented Apr 23, 2019

Closing this issue as its an upstream caveat and the vue ssr docs explicitly warn against this behaviour: Streaming Caveats

@pimlie pimlie closed this as completed Apr 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants