Skip to content

Commit 2e561a3

Browse files
committed
Do not build list of available slots when no error
1 parent 42cfe68 commit 2e561a3

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

packages/react-aria-components/src/utils.tsx

+4-7
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,12 @@ export function useSlottedContext<T>(context: Context<SlottedContextValue<T>>, s
160160
return null;
161161
}
162162
if (ctx && typeof ctx === 'object' && 'slots' in ctx && ctx.slots) {
163-
let availableSlots = new Intl.ListFormat().format(Object.keys(ctx.slots).map(p => `"${p}"`));
164-
165-
if (!slot && !ctx.slots[DEFAULT_SLOT]) {
166-
throw new Error(`A slot prop is required. Valid slot names are ${availableSlots}.`);
167-
}
168163
let slotKey = slot || DEFAULT_SLOT;
169164
if (!ctx.slots[slotKey]) {
170-
// @ts-ignore
171-
throw new Error(`Invalid slot "${slot}". Valid slot names are ${availableSlots}.`);
165+
let availableSlots = new Intl.ListFormat().format(Object.keys(ctx.slots).map(p => `"${p}"`));
166+
let errorMessage = slot ? `Invalid slot "${slot}".` : 'A slot prop is required.';
167+
168+
throw new Error(`${errorMessage} Valid slot names are ${availableSlots}.`);
172169
}
173170
return ctx.slots[slotKey];
174171
}

0 commit comments

Comments
 (0)