Skip to content

Commit 4bd1be0

Browse files
committed
fix(runtime-dom): patch textContent on svg properly
test: improve case chore: improve code chore: improve code chore: improve
1 parent 1c7f5d3 commit 4bd1be0

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

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

Lines changed: 7 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function shouldSetAsProp(
6969
if (isSVG) {
7070
// most keys must be set as attribute on svg elements to work
7171
// ...except innerHTML
72-
if (key === 'innerHTML') {
72+
if (key === 'innerHTML' || key === 'textContent') {
7373
return true
7474
}
7575
// or native onclick with function values

0 commit comments

Comments
 (0)