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

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

Merged
merged 2 commits into from Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/platforms/web/server/modules/attrs.js
Expand Up @@ -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)
}
Expand Down
25 changes: 25 additions & 0 deletions test/ssr/ssr-string.spec.js
Expand Up @@ -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) {
Expand Down