Skip to content

Commit 7e5dc6b

Browse files
authored
fix(ssr): inheritAttrs false adds attributes to html (#11706)
1 parent e0274e4 commit 7e5dc6b

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

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

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export default function renderAttrs (node: VNodeWithData): string {
2525
if (isUndef(opts) || opts.Ctor.options.inheritAttrs !== false) {
2626
let parent = node.parent
2727
while (isDef(parent)) {
28+
// Stop fallthrough in case parent has inheritAttrs option set to false
29+
if (parent.componentOptions && parent.componentOptions.Ctor.options.inheritAttrs === false) {
30+
break;
31+
}
2832
if (isDef(parent.data) && isDef(parent.data.attrs)) {
2933
attrs = extend(extend({}, attrs), parent.data.attrs)
3034
}

test/ssr/ssr-string.spec.js

+25
Original file line numberDiff line numberDiff line change
@@ -1613,6 +1613,31 @@ describe('SSR: renderToString', () => {
16131613
done()
16141614
})
16151615
})
1616+
1617+
it('Options inheritAttrs in parent component', done => {
1618+
const childComponent = {
1619+
template: `<div>{{ someProp }}</div>`,
1620+
props: {
1621+
someProp: {}
1622+
},
1623+
}
1624+
const parentComponent = {
1625+
template: `<childComponent v-bind="$attrs" />`,
1626+
components: { childComponent },
1627+
inheritAttrs: false
1628+
}
1629+
renderVmWithOptions({
1630+
template: `
1631+
<div>
1632+
<parentComponent some-prop="some-val" />
1633+
</div>
1634+
`,
1635+
components: { parentComponent }
1636+
}, result => {
1637+
expect(result).toContain('<div data-server-rendered="true"><div>some-val</div></div>')
1638+
done()
1639+
})
1640+
})
16161641
})
16171642

16181643
function renderVmWithOptions (options, cb) {

0 commit comments

Comments
 (0)