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

[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
Closed

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

kitak opened this issue Jun 14, 2016 · 1 comment
Labels

Comments

@kitak
Copy link

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 [2.0] The elements with v-text or v-html doesn't server-side rendering [2.0] Server-side rendering with v-text or v-html doesn't work well Jun 14, 2016
@yyx990803
Copy link
Member

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

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

2 participants