Browse Source

fix(ssr): inheritAttrs false adds attributes to html (#11706)

dev
Volodymyr I 4 years ago
committed by GitHub
parent
commit
7e5dc6bd9e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      src/platforms/web/server/modules/attrs.js
  2. 25
      test/ssr/ssr-string.spec.js

4
src/platforms/web/server/modules/attrs.js

@ -25,6 +25,10 @@ export default function renderAttrs (node: VNodeWithData): string {
if (isUndef(opts) || opts.Ctor.options.inheritAttrs !== false) {
let parent = node.parent
while (isDef(parent)) {
// Stop fallthrough in case parent has inheritAttrs option set to false
if (parent.componentOptions && parent.componentOptions.Ctor.options.inheritAttrs === false) {
break;
}
if (isDef(parent.data) && isDef(parent.data.attrs)) {
attrs = extend(extend({}, attrs), parent.data.attrs)
}

25
test/ssr/ssr-string.spec.js

@ -1613,6 +1613,31 @@ describe('SSR: renderToString', () => {
done()
})
})
it('Options inheritAttrs in parent component', done => {
const childComponent = {
template: `<div>{{ someProp }}</div>`,
props: {
someProp: {}
},
}
const parentComponent = {
template: `<childComponent v-bind="$attrs" />`,
components: { childComponent },
inheritAttrs: false
}
renderVmWithOptions({
template: `
<div>
<parentComponent some-prop="some-val" />
</div>
`,
components: { parentComponent }
}, result => {
expect(result).toContain('<div data-server-rendered="true"><div>some-val</div></div>')
done()
})
})
})
function renderVmWithOptions (options, cb) {

Loading…
Cancel
Save