vue icon indicating copy to clipboard operation
vue copied to clipboard

vue-server-renderer: directive not applied to imported component

Open manniL opened this issue 4 years ago • 5 comments

What problem does this feature solve?

Currently, SSR directives are not applied to used (sub-)components but only to HTML-tags and elements.

Reproduction

// Step 1: Create a Vue instance
const Vue = require("vue");

const Test = {
  template: `<div>This should be red</div>`
}

const app = new Vue({
  template: `
  <div>
    <Test v-make-red/>
    <div v-make-red>This is red</div>
  </div>
  `,
  components: {
    Test
  }
});

const makeRed = (node, dir) => {
  const style = node.data.style || (node.data.style = {});
  if (Array.isArray(style)) {
    style.push({ backgroundColor: "red" });
  } else {
    style.backgroundColor = "red";
  }
};

// Step 2: Create a renderer
const renderer = require("vue-server-renderer").createRenderer({
  directives: {
    makeRed
  }
});

// Step 3: Render the Vue instance to HTML
renderer.renderToString(app, (err, html) => {
  if (err) throw err;
  console.log(html);
  // <div data-server-rendered="true"><div>This should be red</div> <div style="background-color:red;">This is red</div></div>
  // But should include red background-color style for the first div as well
});

Related: https://github.com/nuxt/nuxt.js/issues/6575

manniL avatar Oct 20 '19 16:10 manniL

hey guys. i use vue on a daily basis and i would like to contribute. I see here this is a contribution welcome label. can someone help me so i can start to fix this if possible?

(i already forked installed and can run test and build.)

dagadbm avatar Jan 22 '20 09:01 dagadbm

Hi, any update on this ? still not working with nuxt 2.14

Neodark7 avatar Oct 14 '20 12:10 Neodark7

Hi, any update on this ? still not working with nuxt 2.14

+1 Still not working, [email protected] [email protected] [email protected]

Dryymoon avatar Nov 26 '20 20:11 Dryymoon

I'm rather confused as to why this fix hasn't been implemented as it appears to completely resolve this issue...

tylerforesthauser avatar Jan 11 '21 16:01 tylerforesthauser

Any update on this?

buffalom avatar Jan 06 '22 16:01 buffalom