Skip to content

Commit

Permalink
Fix crash when children are undefined (#1885)
Browse files Browse the repository at this point in the history
* ensure children always exist

* update changelog
  • Loading branch information
RobinMalfait authored Sep 29, 2022
1 parent 8536838 commit 6cddc0f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/@headlessui-vue/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions packages/@headlessui-vue/src/components/menu/menu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ describe('Safe guards', () => {

describe('Rendering', () => {
describe('Menu', () => {
it('should not crash when rendering no children at all', () => {
renderTemplate(jsx`
<Menu></Menu>
`)
})

it('should be possible to render a Menu using a default render prop', async () => {
renderTemplate(jsx`
<Menu v-slot="{ open }">
Expand Down
2 changes: 1 addition & 1 deletion packages/@headlessui-vue/src/utils/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? []
Expand Down

0 comments on commit 6cddc0f

Please sign in to comment.