From 5df67e36756639ea7b923d1b139d6cb14450123b Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 19 Jul 2024 16:52:03 +0800 Subject: [PATCH] fix(runtime-dom): handle undefined values in v-html (#11403) --- packages/runtime-dom/__tests__/patchProps.spec.ts | 6 ++++++ packages/runtime-dom/src/modules/props.ts | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/runtime-dom/__tests__/patchProps.spec.ts b/packages/runtime-dom/__tests__/patchProps.spec.ts index 7f418847f5..3e7de54a76 100644 --- a/packages/runtime-dom/__tests__/patchProps.spec.ts +++ b/packages/runtime-dom/__tests__/patchProps.spec.ts @@ -152,6 +152,12 @@ describe('runtime-dom: props patching', () => { expect(root.innerHTML).toBe(`
baz
`) }) + test('patch innerHTML porp w/ undefined value', async () => { + const root = document.createElement('div') + render(h('div', { innerHTML: undefined }), root) + expect(root.innerHTML).toBe(`
`) + }) + test('textContent unmount prev children', () => { const fn = vi.fn() const comp = { diff --git a/packages/runtime-dom/src/modules/props.ts b/packages/runtime-dom/src/modules/props.ts index 04f0d0e866..aaacd81972 100644 --- a/packages/runtime-dom/src/modules/props.ts +++ b/packages/runtime-dom/src/modules/props.ts @@ -15,7 +15,7 @@ export function patchDOMProp( if (key === 'innerHTML' || key === 'textContent') { // null value case is handled in renderer patchElement before patching // children - if (value === null) return + if (value == null) return el[key] = value return } -- 2.47.3