fix(system-rsc): correct slot detection in getSlots()#5848
fix(system-rsc): correct slot detection in getSlots()#5848ITBoomBKStudio wants to merge 3 commits into
Conversation
|
@ITBoomBKStudio is attempting to deploy a commit to the HeroUI Inc Team on Vercel. A member of the Team first needs to authorize it. |
🦋 Changeset detectedLatest commit: c878267 The changes in this PR will be included in the next version bump. This PR includes changesets to release 37 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
WalkthroughRefactors getSlots(variants) to a guarded, multi-level traversal with explicit input validation, using a null-prototype accumulator and stricter type checks to collect unique slot names and initialize missing slots; returns {} for invalid input. Public API unchanged. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant C as Caller
participant S as getSlots(variants)
participant V as variants (input)
Note over S: Validation & guarded traversal
C->>S: call getSlots(variants)
S->>V: validate input type
alt invalid
S-->>C: return {}
else valid
S->>S: iterate variant groups
S->>S: iterate configs
S->>S: extract slot names, ignore non-plain objects/arrays/String objects
S->>S: collect unique keys into null-prototype object, init missing to ""
S-->>C: return slots object
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🔇 Additional comments (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/core/system-rsc/src/extend-variants.js (1)
7-34: Well-structured refactoring that fixes the array indexing issue.The explicit multi-level traversal with type guards correctly prevents numeric array indices from being extracted as slot names. The null-prototype accumulator and defensive
hasOwnPropertycheck provide good protection against prototype pollution. The logic properly handles edge cases (null/undefined groups, arrays, String objects).Consider adding a brief JSDoc comment explaining the expected variants structure and why String objects are explicitly checked:
+/** + * 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) { 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; }
@heroui/accordion
@heroui/alert
@heroui/autocomplete
@heroui/avatar
@heroui/badge
@heroui/breadcrumbs
@heroui/button
@heroui/calendar
@heroui/card
@heroui/checkbox
@heroui/chip
@heroui/code
@heroui/date-input
@heroui/date-picker
@heroui/divider
@heroui/drawer
@heroui/dropdown
@heroui/form
@heroui/image
@heroui/input
@heroui/input-otp
@heroui/kbd
@heroui/link
@heroui/listbox
@heroui/menu
@heroui/modal
@heroui/navbar
@heroui/number-input
@heroui/pagination
@heroui/popover
@heroui/progress
@heroui/radio
@heroui/ripple
@heroui/scroll-shadow
@heroui/select
@heroui/skeleton
@heroui/slider
@heroui/snippet
@heroui/spacer
@heroui/spinner
@heroui/switch
@heroui/table
@heroui/tabs
@heroui/toast
@heroui/tooltip
@heroui/user
@heroui/react
@heroui/system
@heroui/system-rsc
@heroui/theme
@heroui/use-aria-accordion
@heroui/use-aria-accordion-item
@heroui/use-aria-button
@heroui/use-aria-link
@heroui/use-aria-modal-overlay
@heroui/use-aria-multiselect
@heroui/use-aria-overlay
@heroui/use-callback-ref
@heroui/use-clipboard
@heroui/use-data-scroll-overflow
@heroui/use-disclosure
@heroui/use-draggable
@heroui/use-form-reset
@heroui/use-image
@heroui/use-infinite-scroll
@heroui/use-intersection-observer
@heroui/use-is-mobile
@heroui/use-is-mounted
@heroui/use-measure
@heroui/use-pagination
@heroui/use-real-shape
@heroui/use-ref-state
@heroui/use-resize
@heroui/use-safe-layout-effect
@heroui/use-scroll-position
@heroui/use-ssr
@heroui/use-theme
@heroui/use-update-effect
@heroui/use-viewport-size
@heroui/aria-utils
@heroui/dom-animation
@heroui/framer-utils
@heroui/react-rsc-utils
@heroui/react-utils
@heroui/shared-icons
@heroui/shared-utils
@heroui/stories-utils
@heroui/test-utils
commit: |
|
As mentioned in #5847 please merge the changes to the linked PR. Also please include some test cases and examples in your description (i.e. before & after). Thanks. |
📝 Description
Fixes incorrect slot detection in the getSlots() helper.
This PR corrects how slot keys are collected from the variants object.
The previous implementation iterated over variant values and sometimes extracted wrong keys (for example numeric indices from arrays), which caused invalid or missing slot names in the resulting slots map.
The new logic walks through each variant group and its configs, gathering slot keys from nested objects while safely ignoring non-object values.
Related to #5847 — follow-up improvement that complements the extendVariants typing fixes.
⛳️ Current behavior (updates)
• getSlots() may return incorrect or incomplete slot maps.
• compoundVariants often fail to apply classes when extending a component, because slot names do not match those of the base component.
🚀 New behavior
• Correctly extracts all slot keys from variant configurations, including base component slots.
• compoundVariants.class.{slot} now applies reliably.
• Ignores arrays, strings, and non-plain objects to avoid noise.
💣 Is this a breaking change (Yes/No):
No.
📝 Additional Information
• Keeps compatibility with existing variant definitions.
• Tested with components that extend base slots (value, trigger, label, input, base, etc.).
• Complements the type-level PR #5847 which addressed CompoundVariants inference.
Summary by CodeRabbit
Refactor
Chores