diff --git a/.changeset/four-guests-sneeze.md b/.changeset/four-guests-sneeze.md new file mode 100644 index 0000000000..c6f4661953 --- /dev/null +++ b/.changeset/four-guests-sneeze.md @@ -0,0 +1,5 @@ +--- +"@heroui/system-rsc": minor +--- + +fix(system-rsc): correct slot detection in getSlots() to ensure proper slot key extraction and consistent compoundVariants behavior. diff --git a/packages/core/system-rsc/src/extend-variants.js b/packages/core/system-rsc/src/extend-variants.js index f91957acab..a199400e1f 100644 --- a/packages/core/system-rsc/src/extend-variants.js +++ b/packages/core/system-rsc/src/extend-variants.js @@ -4,22 +4,40 @@ import clsx from "clsx"; import {mapPropsVariants} from "./utils"; +/** + * Extracts slot names from variant configurations. + * Traverses: variants -> variant groups -> variant configs -> slot names + * @param {Object} variants - Nested object: { variantName: { value: { slotName: "...", ... } } } + * @returns {Object} Map of slot names to empty strings + */ function getSlots(variants) { - return variants - ? Object.values(variants) - .flatMap(Object.values) - .reduce((acc, slot) => { - if (typeof slot === "object" && slot !== null && !(slot instanceof String)) { - Object.keys(slot).forEach((key) => { - if (!acc.hasOwnProperty(key)) { - acc[key] = ""; - } - }); - } - - return acc; - }, {}) - : {}; + if (!variants || typeof variants !== "object") return {}; + + const acc = Object.create(null); + + for (const group of Object.values(variants)) { + if (!group || typeof group !== "object") continue; + + for (const config of Object.values(group)) { + // Skip non-objects, arrays (which would yield numeric indices), and String objects + if ( + !config || + typeof config !== "object" || + Array.isArray(config) || + config instanceof String + ) { + continue; + } + + for (const slotName of Object.keys(config)) { + if (!Object.prototype.hasOwnProperty.call(acc, slotName)) { + acc[slotName] = ""; + } + } + } + } + + return acc; } function getClassNamesWithProps({