]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-dom): patch `textContent` on svg properly (#4301)
authoredison <daiwei521@126.com>
Wed, 11 Aug 2021 14:53:54 +0000 (22:53 +0800)
committerGitHub <noreply@github.com>
Wed, 11 Aug 2021 14:53:54 +0000 (10:53 -0400)
fix #4296

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

index 932c4a589cc5457c66e623a78f28efc4c93ddeac..ca48c10fea2d28bd941f1404499527b96618b812 100644 (file)
@@ -10,6 +10,13 @@ describe('runtime-dom: attrs patching', () => {
     expect(el.getAttributeNS(xlinkNS, 'href')).toBe(null)
   })
 
+  test('textContent attributes /w svg', () => {
+    const el = document.createElementNS('http://www.w3.org/2000/svg', 'use')
+    patchProp(el, 'textContent', null, 'foo', true)
+    expect(el.attributes.length).toBe(0)
+    expect(el.innerHTML).toBe('foo')
+  })
+
   test('boolean attributes', () => {
     const el = document.createElement('input')
     patchProp(el, 'readonly', null, true)
index c92bbfb56ef08535c55585dd555dde8f7c77686f..e10d189c581f1e653041ccc65ea8096586609190 100644 (file)
@@ -68,8 +68,8 @@ function shouldSetAsProp(
 ) {
   if (isSVG) {
     // most keys must be set as attribute on svg elements to work
-    // ...except innerHTML
-    if (key === 'innerHTML') {
+    // ...except innerHTML & textContent
+    if (key === 'innerHTML' || key === 'textContent') {
       return true
     }
     // or native onclick with function values