]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-dom): handle undefined values in v-html (#11403)
authorTycho <jh.leong@outlook.com>
Fri, 19 Jul 2024 08:52:03 +0000 (16:52 +0800)
committerGitHub <noreply@github.com>
Fri, 19 Jul 2024 08:52:03 +0000 (16:52 +0800)
packages/runtime-dom/__tests__/patchProps.spec.ts
packages/runtime-dom/src/modules/props.ts

index 7f418847f5f8a854398ca5d6f1a0714e3b004a7e..3e7de54a767364f04d8bb9d82dbd890b09f45bf4 100644 (file)
@@ -152,6 +152,12 @@ describe('runtime-dom: props patching', () => {
     expect(root.innerHTML).toBe(`<div><del>baz</del></div>`)
   })
 
+  test('patch innerHTML porp w/ undefined value', async () => {
+    const root = document.createElement('div')
+    render(h('div', { innerHTML: undefined }), root)
+    expect(root.innerHTML).toBe(`<div></div>`)
+  })
+
   test('textContent unmount prev children', () => {
     const fn = vi.fn()
     const comp = {
index 04f0d0e866d48c342dd6e56b112212827981b7fa..aaacd81972cc8999bffc2b1fb94927e3d1623285 100644 (file)
@@ -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
   }