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
bug

Comments

@kitak
Copy link

@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 [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 yyx990803 added bug 2.0 labels Jun 14, 2016
yyx990803 added a commit that referenced this issue Jun 14, 2016
@yyx990803
Copy link
Member

@yyx990803 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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.