question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:5

github_iconTop GitHub Comments

6reactions
dagadbmcommented, Jan 22, 2020

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.)

1reaction
Dryymooncommented, Nov 26, 2020

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

+1 Still not working, nuxt@2.14.6 vue@2.6.12 vue-server-renderer@2.6.12

Read more comments on GitHub >

github_iconTop Results From Across the Web

I have problem with new v-directive in nuxt3 project
i correctly implemented the primevue free component but when i try to use primeblock components ... Single component works, directive no
Read more >
Server-Side Rendering (SSR) - Vue.js
The keyword here is static: SSG can only be applied to pages consuming static data, i.e. data that is known at build time...
Read more >
vuejs custom directive does not seem to register
In the component where you want to use it, you would import autosize from "components/directives/autosize.js" and then you would have directives ...
Read more >
vue-server-renderer | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
v-font - Nuxt Speedkit
The directive v-font is used to integrate the fonts defined in the module ... Read more: vue-server-renderer: directive not applied to imported component...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found