Skip to content

Commit 6cddc0f

Browse files
authored
Fix crash when children are undefined (#1885)
* ensure children always exist * update changelog
1 parent 8536838 commit 6cddc0f

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

packages/@headlessui-vue/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Call `displayValue` with a v-model of `ref(undefined)` on `ComboboxInput` ([#1865](https://github.com/tailwindlabs/headlessui/pull/1865))
1313
- Improve `Portal` detection for `Popover` components ([#1842](https://github.com/tailwindlabs/headlessui/pull/1842))
14+
- Fix crash when `children` are `undefined` ([#1885](https://github.com/tailwindlabs/headlessui/pull/1885))
1415

1516
## [1.7.2] - 2022-09-15
1617

packages/@headlessui-vue/src/components/menu/menu.test.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ describe('Safe guards', () => {
9191

9292
describe('Rendering', () => {
9393
describe('Menu', () => {
94+
it('should not crash when rendering no children at all', () => {
95+
renderTemplate(jsx`
96+
<Menu></Menu>
97+
`)
98+
})
99+
94100
it('should be possible to render a Menu using a default render prop', async () => {
95101
renderTemplate(jsx`
96102
<Menu v-slot="{ open }">

packages/@headlessui-vue/src/utils/render.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ function _render({
108108
}
109109

110110
if (as === 'template') {
111-
children = flattenFragments(children as VNode[])
111+
children = flattenFragments(children ?? [])
112112

113113
if (Object.keys(incomingProps).length > 0 || Object.keys(attrs).length > 0) {
114114
let [firstChild, ...other] = children ?? []

0 commit comments

Comments
 (0)