Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime-core): fix empty fragment in runtime-core #10010

Merged
merged 3 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/runtime-core/__tests__/rendererFragment.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('')
})
})
6 changes: 5 additions & 1 deletion packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down