Skip to content

Commit

Permalink
Do not build list of available slots when no error (#7731)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorrit authored Feb 6, 2025
1 parent 42cfe68 commit ac55911
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions packages/react-aria-components/src/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,12 @@ export function useSlottedContext<T>(context: Context<SlottedContextValue<T>>, 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];
}
Expand Down

1 comment on commit ac55911

@rspbot
Copy link

@rspbot rspbot commented on ac55911 Feb 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.