Fix crash when children are undefined (#1885)

* ensure children always exist

* update changelog
This commit is contained in:
Robin Malfait
2022-09-29 12:00:15 +02:00
committed by GitHub
parent 8536838bb3
commit 6cddc0fc8a
3 changed files with 8 additions and 1 deletions
+1
View File
@@ -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
@@ -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 }">
+1 -1
View File
@@ -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 ?? []