From 4bd1be0836da0232c658b8d0ea10a1f22ecc9388 Mon Sep 17 00:00:00 2001 From: daiwei Date: Wed, 11 Aug 2021 09:58:25 +0800 Subject: [PATCH] fix(runtime-dom): patch `textContent` on svg properly test: improve case chore: improve code chore: improve code chore: improve --- packages/runtime-dom/__tests__/patchAttrs.spec.ts | 7 +++++++ packages/runtime-dom/src/patchProp.ts | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/runtime-dom/__tests__/patchAttrs.spec.ts b/packages/runtime-dom/__tests__/patchAttrs.spec.ts index 932c4a589cc..ca48c10fea2 100644 --- a/packages/runtime-dom/__tests__/patchAttrs.spec.ts +++ b/packages/runtime-dom/__tests__/patchAttrs.spec.ts @@ -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) diff --git a/packages/runtime-dom/src/patchProp.ts b/packages/runtime-dom/src/patchProp.ts index c92bbfb56ef..23315cd0437 100644 --- a/packages/runtime-dom/src/patchProp.ts +++ b/packages/runtime-dom/src/patchProp.ts @@ -69,7 +69,7 @@ function shouldSetAsProp( if (isSVG) { // most keys must be set as attribute on svg elements to work // ...except innerHTML - if (key === 'innerHTML') { + if (key === 'innerHTML' || key === 'textContent') { return true } // or native onclick with function values