From 7e5dc6bd9ebc1620624191804d2ace43cae557a8 Mon Sep 17 00:00:00 2001 From: Volodymyr I Date: Tue, 30 Mar 2021 11:49:40 +0200 Subject: [PATCH] fix(ssr): inheritAttrs false adds attributes to html (#11706) --- src/platforms/web/server/modules/attrs.js | 4 ++++ test/ssr/ssr-string.spec.js | 25 +++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/platforms/web/server/modules/attrs.js b/src/platforms/web/server/modules/attrs.js index 4d48eeed2da..e575d13ae30 100644 --- a/src/platforms/web/server/modules/attrs.js +++ b/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) } diff --git a/test/ssr/ssr-string.spec.js b/test/ssr/ssr-string.spec.js index b24f7e024b5..61abfce9a2f 100644 --- a/test/ssr/ssr-string.spec.js +++ b/test/ssr/ssr-string.spec.js @@ -1613,6 +1613,31 @@ describe('SSR: renderToString', () => { done() }) }) + + it('Options inheritAttrs in parent component', done => { + const childComponent = { + template: `
{{ someProp }}
`, + props: { + someProp: {} + }, + } + const parentComponent = { + template: ``, + components: { childComponent }, + inheritAttrs: false + } + renderVmWithOptions({ + template: ` +
+ +
+ `, + components: { parentComponent } + }, result => { + expect(result).toContain('
some-val
') + done() + }) + }) }) function renderVmWithOptions (options, cb) {