fix(ssr): respect case when rendering dynamic attrs on svg

fix #6755
This commit is contained in:
Evan You 2022-09-27 17:40:22 +08:00
parent 6958ec1b37
commit 121eb32fb0
2 changed files with 14 additions and 3 deletions

View File

@ -98,6 +98,17 @@ describe('ssr: renderAttrs', () => {
) )
).toBe(` fooBar="ok"`) ).toBe(` fooBar="ok"`)
}) })
test('preserve name on svg elements', () => {
expect(
ssrRenderAttrs(
{
viewBox: 'foo'
},
'svg'
)
).toBe(` viewBox="foo"`)
})
}) })
describe('ssr: renderAttr', () => { describe('ssr: renderAttr', () => {

View File

@ -1,4 +1,4 @@
import { escapeHtml, stringifyStyle } from '@vue/shared' import { escapeHtml, isSVGTag, stringifyStyle } from '@vue/shared'
import { import {
normalizeClass, normalizeClass,
normalizeStyle, normalizeStyle,
@ -51,8 +51,8 @@ export function ssrRenderDynamicAttr(
return `` return ``
} }
const attrKey = const attrKey =
tag && tag.indexOf('-') > 0 tag && (tag.indexOf('-') > 0 || isSVGTag(tag))
? key // preserve raw name on custom elements ? key // preserve raw name on custom elements and svg
: propsToAttrMap[key] || key.toLowerCase() : propsToAttrMap[key] || key.toLowerCase()
if (isBooleanAttr(attrKey)) { if (isBooleanAttr(attrKey)) {
return includeBooleanAttr(value) ? ` ${attrKey}` : `` return includeBooleanAttr(value) ? ` ${attrKey}` : ``