Skip to content

Commit

Permalink
fix(ssr): respect case when rendering dynamic attrs on svg
Browse files Browse the repository at this point in the history
fix #6755
  • Loading branch information
yyx990803 committed Sep 27, 2022
1 parent 6958ec1 commit 121eb32
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 11 additions & 0 deletions packages/server-renderer/__tests__/ssrRenderAttrs.spec.ts
Expand Up @@ -98,6 +98,17 @@ describe('ssr: renderAttrs', () => {
)
).toBe(` fooBar="ok"`)
})

test('preserve name on svg elements', () => {
expect(
ssrRenderAttrs(
{
viewBox: 'foo'
},
'svg'
)
).toBe(` viewBox="foo"`)
})
})

describe('ssr: renderAttr', () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/server-renderer/src/helpers/ssrRenderAttrs.ts
@@ -1,4 +1,4 @@
import { escapeHtml, stringifyStyle } from '@vue/shared'
import { escapeHtml, isSVGTag, stringifyStyle } from '@vue/shared'
import {
normalizeClass,
normalizeStyle,
Expand Down Expand Up @@ -51,8 +51,8 @@ export function ssrRenderDynamicAttr(
return ``
}
const attrKey =
tag && tag.indexOf('-') > 0
? key // preserve raw name on custom elements
tag && (tag.indexOf('-') > 0 || isSVGTag(tag))
? key // preserve raw name on custom elements and svg
: propsToAttrMap[key] || key.toLowerCase()
if (isBooleanAttr(attrKey)) {
return includeBooleanAttr(value) ? ` ${attrKey}` : ``
Expand Down

0 comments on commit 121eb32

Please sign in to comment.