[2.0] Server-side rendering with v-text or v-html doesn't work well #3078

Closed
kitak opened this Issue Jun 14, 2016 · 1 comment

Comments

Projects
None yet
2 participants
@kitak

kitak commented Jun 14, 2016

Hi, I try to use renderToString to the elements with v-text or v-html. It doesn't work well.

This is the code to reproduce.

import Vue from './vue/dist/vue.common.js';
import { compileToFunctions } from './vue/packages/vue-template-compiler';
import createRenderer from './vue/packages/vue-server-renderer';
const { renderToString } = createRenderer();

let compileTemplate = (options) => {
  const res = compileToFunctions(options.template, {
    preserveWhitespace: false
  });
  Object.assign(options, res);
  console.assert(typeof options.render === 'function');
  delete options.template;
  return options;
};

let Foo = Vue.extend(compileTemplate({
  template: `
<div>
  <p v-text="text"></p>
  <p v-html="text"></p>
</div>
  `,
  data: function() {
    return {
      text: '<span>foobar</span>',
    };
  }
}));

renderToString(new Vue(compileTemplate({
  template: `<foo></foo>`,
  components: {
    foo: Foo
  }
})), (err, res) => {
  console.log(res);
});

// output: <div server-rendered="true"><p></p> <p></p></div>

Is this a bug or a feature? It seems to be resolved in this fix ( kitak@8d46106 ). If it is good, I will send PullRequest.

@kitak kitak changed the title from [2.0] The elements with v-text or v-html doesn't server-side rendering to [2.0] Server-side rendering with v-text or v-html doesn't work well Jun 14, 2016

@yyx990803 yyx990803 added bug 2.0 labels Jun 14, 2016

yyx990803 added a commit that referenced this issue Jun 14, 2016

@yyx990803

This comment has been minimized.

Show comment
Hide comment
@yyx990803

yyx990803 Jun 14, 2016

Member

Thanks for reporting the issue! The fix involves some other changes so I fixed it with some additional refactoring.

Member

yyx990803 commented Jun 14, 2016

Thanks for reporting the issue! The fix involves some other changes so I fixed it with some additional refactoring.

@yyx990803 yyx990803 closed this Jun 14, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment