Skip to content

Commit e7b0a9d

Browse files
authored
fix(runtime-dom): patch textContent on svg properly (#4301)
fix #4296
1 parent 1ce34e2 commit e7b0a9d

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

packages/runtime-dom/__tests__/patchAttrs.spec.ts

+7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ describe('runtime-dom: attrs patching', () => {
1010
expect(el.getAttributeNS(xlinkNS, 'href')).toBe(null)
1111
})
1212

13+
test('textContent attributes /w svg', () => {
14+
const el = document.createElementNS('http://www.w3.org/2000/svg', 'use')
15+
patchProp(el, 'textContent', null, 'foo', true)
16+
expect(el.attributes.length).toBe(0)
17+
expect(el.innerHTML).toBe('foo')
18+
})
19+
1320
test('boolean attributes', () => {
1421
const el = document.createElement('input')
1522
patchProp(el, 'readonly', null, true)

packages/runtime-dom/src/patchProp.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ function shouldSetAsProp(
6868
) {
6969
if (isSVG) {
7070
// most keys must be set as attribute on svg elements to work
71-
// ...except innerHTML
72-
if (key === 'innerHTML') {
71+
// ...except innerHTML & textContent
72+
if (key === 'innerHTML' || key === 'textContent') {
7373
return true
7474
}
7575
// or native onclick with function values

0 commit comments

Comments
 (0)