From e7b0a9d3cffc938d3add7dcde02d0991f60c6ec9 Mon Sep 17 00:00:00 2001 From: edison Date: Wed, 11 Aug 2021 22:53:54 +0800 Subject: [PATCH] fix(runtime-dom): patch `textContent` on svg properly (#4301) fix #4296 --- packages/runtime-dom/__tests__/patchAttrs.spec.ts | 7 +++++++ packages/runtime-dom/src/patchProp.ts | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/runtime-dom/__tests__/patchAttrs.spec.ts b/packages/runtime-dom/__tests__/patchAttrs.spec.ts index 932c4a58..ca48c10f 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 c92bbfb5..e10d189c 100644 --- a/packages/runtime-dom/src/patchProp.ts +++ b/packages/runtime-dom/src/patchProp.ts @@ -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