Просмотр исходного кода

fix(runtime-dom): handle undefined values in v-html (#11403)

Tycho 1 год назад
Родитель
Сommit
5df67e3675

+ 6 - 0
packages/runtime-dom/__tests__/patchProps.spec.ts

@@ -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 = {

+ 1 - 1
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
   }