From 15e707c4ad431908e359d4dbe62b94c837ac1409 Mon Sep 17 00:00:00 2001 From: Benjamin Canac Date: Thu, 6 Jun 2024 15:08:10 +0200 Subject: [PATCH] chore(CommandPalette): warn when group is missing `id` --- src/runtime/components/CommandPalette.vue | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/runtime/components/CommandPalette.vue b/src/runtime/components/CommandPalette.vue index 981bb280..47e6fb53 100644 --- a/src/runtime/components/CommandPalette.vue +++ b/src/runtime/components/CommandPalette.vue @@ -104,7 +104,14 @@ const fuse = computed(() => defu({}, props.fuse, { matchAllWhenSearchEmpty: true })) -const items = computed(() => props.groups?.flatMap(group => group.items?.map(item => ({ ...item, group: group.id })) || []) || []) +const items = computed(() => props.groups?.filter((group) => { + if (!group.id) { + console.warn(`[@nuxt/ui] CommandPalette group is missing an \`id\` property`) + return false + } + + return true +}).flatMap(group => group.items?.map(item => ({ ...item, group: group.id })) || []) || []) const { results: fuseResults } = useFuse(searchTerm, items, fuse)