]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): handle fragment with null children (#10010)
authorDoctorwu <44631608+Doctor-wu@users.noreply.github.com>
Mon, 8 Jan 2024 10:48:47 +0000 (18:48 +0800)
committerGitHub <noreply@github.com>
Mon, 8 Jan 2024 10:48:47 +0000 (18:48 +0800)
close #10007

packages/runtime-core/__tests__/rendererFragment.spec.ts
packages/runtime-core/src/renderer.ts

index a8299ef93dfd25e39a66d95979173391ae3ccfe6..5f1e869366fb0dc4c132b0771aaed84d7ff38bd5 100644 (file)
@@ -351,4 +351,16 @@ describe('renderer: fragment', () => {
     render(renderFn(['two', 'one']), root)
     expect(serializeInner(root)).toBe(`text<div>two</div>text<div>one</div>`)
   })
+
+  // #10007
+  test('empty fragment', () => {
+    const root = nodeOps.createElement('div')
+
+    const renderFn = () => {
+      return openBlock(true), createBlock(Fragment, null)
+    }
+
+    render(renderFn(), root)
+    expect(serializeInner(root)).toBe('')
+  })
 })
index cb141d216ffacaefea989a46ca7a572ac6e3d8e4..c7dfbf45dd220e6c8c82e2a4c8b63e9e8686b555 100644 (file)
@@ -1086,7 +1086,11 @@ function baseCreateRenderer(
       // since they are either generated by the compiler, or implicitly created
       // from arrays.
       mountChildren(
-        n2.children as VNodeArrayChildren,
+        // #10007
+        // such fragment like `<></>` will be compiled into
+        // a fragment which doesn't have a children.
+        // In this case fallback to an empty array
+        (n2.children || []) as VNodeArrayChildren,
         container,
         fragmentEndAnchor,
         parentComponent,