From 6cddc0fc8acbbd2c8b9c4dc6ffe4d6d9621d77fd Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Thu, 29 Sep 2022 12:00:15 +0200 Subject: [PATCH] Fix crash when `children` are `undefined` (#1885) * ensure children always exist * update changelog --- packages/@headlessui-vue/CHANGELOG.md | 1 + packages/@headlessui-vue/src/components/menu/menu.test.tsx | 6 ++++++ packages/@headlessui-vue/src/utils/render.ts | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/@headlessui-vue/CHANGELOG.md b/packages/@headlessui-vue/CHANGELOG.md index 9d567bb32f..18329d64a9 100644 --- a/packages/@headlessui-vue/CHANGELOG.md +++ b/packages/@headlessui-vue/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Call `displayValue` with a v-model of `ref(undefined)` on `ComboboxInput` ([#1865](https://github.com/tailwindlabs/headlessui/pull/1865)) - Improve `Portal` detection for `Popover` components ([#1842](https://github.com/tailwindlabs/headlessui/pull/1842)) +- Fix crash when `children` are `undefined` ([#1885](https://github.com/tailwindlabs/headlessui/pull/1885)) ## [1.7.2] - 2022-09-15 diff --git a/packages/@headlessui-vue/src/components/menu/menu.test.tsx b/packages/@headlessui-vue/src/components/menu/menu.test.tsx index b73eee3aeb..ab408c2bc1 100644 --- a/packages/@headlessui-vue/src/components/menu/menu.test.tsx +++ b/packages/@headlessui-vue/src/components/menu/menu.test.tsx @@ -91,6 +91,12 @@ describe('Safe guards', () => { describe('Rendering', () => { describe('Menu', () => { + it('should not crash when rendering no children at all', () => { + renderTemplate(jsx` + + `) + }) + it('should be possible to render a Menu using a default render prop', async () => { renderTemplate(jsx` diff --git a/packages/@headlessui-vue/src/utils/render.ts b/packages/@headlessui-vue/src/utils/render.ts index f8781b00ee..c75c80afdf 100644 --- a/packages/@headlessui-vue/src/utils/render.ts +++ b/packages/@headlessui-vue/src/utils/render.ts @@ -108,7 +108,7 @@ function _render({ } if (as === 'template') { - children = flattenFragments(children as VNode[]) + children = flattenFragments(children ?? []) if (Object.keys(incomingProps).length > 0 || Object.keys(attrs).length > 0) { let [firstChild, ...other] = children ?? []