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

vue-server-renderer: inheritAttrs false doesn't work properly #11297

Closed
ArtemyNv opened this issue Apr 8, 2020 · 1 comment · Fixed by #11706
Closed

vue-server-renderer: inheritAttrs false doesn't work properly #11297

ArtemyNv opened this issue Apr 8, 2020 · 1 comment · Fixed by #11706

Comments

@ArtemyNv
Copy link

ArtemyNv commented Apr 8, 2020

Version

2.6.11

Reproduction link

https://github.com/Tibon4ik/vue-server-renderer-inherit-attrs

Steps to reproduce

Clone the repo

  • $ npm install
  • $ npm run test

Or:

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

const AppCard = {
  template: `<div>appCardProp: {{ appCardProp }}</div>`,
  props: {
    appCardProp: {}
  }
}

const PlayerCard = {
  template: `<AppCard v-bind="$attrs" />`,
  components: { AppCard },
  inheritAttrs: false
}

const app = new Vue({
  template: `
  <div>
    <PlayerCard app-card-prop="appCardProp value" />
  </div>
  `,
  components: { PlayerCard }
});

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

// 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 app-card-prop="appCardProp value">appCardProp: appCardProp value</div></div>
  // Html attribute "app-card-prop" must be missing
});

What is expected?

<div data-server-rendered="true">
  <div>
    appCardProp: appCardProp value
  </div>
</div>

What is actually happening?

<div data-server-rendered="true">
  <div app-card-prop="appCardProp value">
    appCardProp: appCardProp value
  </div>
</div>

This bug happens when i use component with inheritAttrs: false, which use another component on top level of section or render function.

I want to pass props to inner component with v-bind="$attrs" and inheritAttrs: false. It passes props inside but still adds attributes to html element.

I noticed that this bug doesn't occur in next cases:

  • if i set inheritAttrs: false on inner component (AppCard of code section).
  • if top level of "template" or render function is not a component (e.g. simple "div" or "span").

Related: nuxt/nuxt#7195

@noreff
Copy link
Contributor

noreff commented Oct 5, 2020

If nobody don't mind I will try my best to solve it and push some PR later

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

Successfully merging a pull request may close this issue.

3 participants