From 2e561a37eb81c5f666d66de33f80f717998005ec Mon Sep 17 00:00:00 2001 From: Jorrit Schippers Date: Thu, 6 Feb 2025 09:33:41 +0100 Subject: [PATCH] Do not build list of available slots when no error --- packages/react-aria-components/src/utils.tsx | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/react-aria-components/src/utils.tsx b/packages/react-aria-components/src/utils.tsx index 4f57ecfc00e..8a8d8ae9e3a 100644 --- a/packages/react-aria-components/src/utils.tsx +++ b/packages/react-aria-components/src/utils.tsx @@ -160,15 +160,12 @@ export function useSlottedContext(context: Context>, s return null; } if (ctx && typeof ctx === 'object' && 'slots' in ctx && ctx.slots) { - let availableSlots = new Intl.ListFormat().format(Object.keys(ctx.slots).map(p => `"${p}"`)); - - if (!slot && !ctx.slots[DEFAULT_SLOT]) { - throw new Error(`A slot prop is required. Valid slot names are ${availableSlots}.`); - } let slotKey = slot || DEFAULT_SLOT; if (!ctx.slots[slotKey]) { - // @ts-ignore - throw new Error(`Invalid slot "${slot}". Valid slot names are ${availableSlots}.`); + let availableSlots = new Intl.ListFormat().format(Object.keys(ctx.slots).map(p => `"${p}"`)); + let errorMessage = slot ? `Invalid slot "${slot}".` : 'A slot prop is required.'; + + throw new Error(`${errorMessage} Valid slot names are ${availableSlots}.`); } return ctx.slots[slotKey]; }