@@ -315,32 +315,30 @@ export class ResponsiveCodegen {
315315 componentSet : ComponentSetNode ,
316316 componentName : string ,
317317 ) : Promise < ReadonlyArray < readonly [ string , string ] > > {
318- // Find viewport variant key
319- const viewportKey = Object . keys (
320- componentSet . componentPropertyDefinitions ,
321- ) . find ( ( key ) => key . toLowerCase ( ) === 'viewport' )
318+ // Find viewport and effect variant keys
319+ let viewportKey : string | undefined
320+ let effectKey : string | undefined
321+ for ( const key in componentSet . componentPropertyDefinitions ) {
322+ const lower = key . toLowerCase ( )
323+ if ( lower === 'viewport' ) viewportKey = key
324+ else if ( lower === 'effect' ) effectKey = key
325+ }
322326
323327 if ( ! viewportKey ) {
324328 return [ ]
325329 }
326330
327331 // Get variants excluding viewport
328332 const variants : Record < string , string > = { }
329- for ( const [ name , definition ] of Object . entries (
330- componentSet . componentPropertyDefinitions ,
331- ) ) {
333+ for ( const name in componentSet . componentPropertyDefinitions ) {
334+ const definition = componentSet . componentPropertyDefinitions [ name ]
332335 if ( name . toLowerCase ( ) !== 'viewport' && definition . type === 'VARIANT' ) {
333336 const sanitizedName = sanitizePropertyName ( name )
334337 variants [ sanitizedName ] =
335338 definition . variantOptions ?. map ( ( opt ) => `'${ opt } '` ) . join ( ' | ' ) || ''
336339 }
337340 }
338341
339- // Find effect variant key (to exclude from grouping)
340- const effectKey = Object . keys (
341- componentSet . componentPropertyDefinitions ,
342- ) . find ( ( key ) => key . toLowerCase ( ) === 'effect' )
343-
344342 // Group components by non-viewport, non-effect variants
345343 const groups = new Map < string , Map < BreakpointKey , ComponentNode > > ( )
346344
@@ -358,16 +356,15 @@ export class ResponsiveCodegen {
358356
359357 const breakpoint = viewportToBreakpoint ( viewportValue )
360358 // Create group key from non-viewport, non-effect variants
361- const otherVariants = Object . entries ( variantProps )
362- . filter ( ( [ key ] ) => {
363- const lowerKey = key . toLowerCase ( )
364- return lowerKey !== 'viewport' && lowerKey !== 'effect'
365- } )
366- . sort ( ( [ a ] , [ b ] ) => a . localeCompare ( b ) )
367- . map ( ( [ key , value ] ) => `${ key } =${ value } ` )
368- . join ( '|' )
369-
370- const groupKey = otherVariants || '__default__'
359+ const parts : string [ ] = [ ]
360+ for ( const key in variantProps ) {
361+ const lowerKey = key . toLowerCase ( )
362+ if ( lowerKey !== 'viewport' && lowerKey !== 'effect' ) {
363+ parts . push ( `${ key } =${ variantProps [ key ] } ` )
364+ }
365+ }
366+ parts . sort ( ( a , b ) => ( a < b ? - 1 : a > b ? 1 : 0 ) )
367+ const groupKey = parts . join ( '|' ) || '__default__'
371368
372369 if ( ! groups . has ( groupKey ) ) {
373370 groups . set ( groupKey , new Map ( ) )
@@ -415,7 +412,7 @@ export class ResponsiveCodegen {
415412 )
416413 perfEnd ( 'getSelectorPropsForGroup(viewport)' , t )
417414 if ( Object . keys ( selectorProps ) . length > 0 ) {
418- tree . props = { ... tree . props , ... selectorProps }
415+ tree . props = Object . assign ( { } , tree . props , selectorProps )
419416 }
420417 }
421418
@@ -454,24 +451,22 @@ export class ResponsiveCodegen {
454451 )
455452 const tTotal = perfStart ( )
456453
457- // Find viewport variant key
458- const viewportKey = Object . keys (
459- componentSet . componentPropertyDefinitions ,
460- ) . find ( ( key ) => key . toLowerCase ( ) === 'viewport' )
461-
462- // Find effect variant key
463- const effectKey = Object . keys (
464- componentSet . componentPropertyDefinitions ,
465- ) . find ( ( key ) => key . toLowerCase ( ) === 'effect' )
454+ // Find viewport and effect variant keys
455+ let viewportKey : string | undefined
456+ let effectKey : string | undefined
457+ for ( const key in componentSet . componentPropertyDefinitions ) {
458+ const lower = key . toLowerCase ( )
459+ if ( lower === 'viewport' ) viewportKey = key
460+ else if ( lower === 'effect' ) effectKey = key
461+ }
466462
467463 // Get all variant keys excluding viewport and effect
468464 const otherVariantKeys : string [ ] = [ ]
469465 const variants : Record < string , string > = { }
470466 // Map from original name to sanitized name
471467 const variantKeyToSanitized : Record < string , string > = { }
472- for ( const [ name , definition ] of Object . entries (
473- componentSet . componentPropertyDefinitions ,
474- ) ) {
468+ for ( const name in componentSet . componentPropertyDefinitions ) {
469+ const definition = componentSet . componentPropertyDefinitions [ name ]
475470 if ( definition . type === 'VARIANT' ) {
476471 const lowerName = name . toLowerCase ( )
477472 // Exclude both viewport and effect from variant keys
@@ -628,7 +623,7 @@ export class ResponsiveCodegen {
628623 )
629624 perfEnd ( 'getSelectorPropsForGroup()' , t )
630625 if ( Object . keys ( selectorProps ) . length > 0 ) {
631- tree . props = { ... tree . props , ... selectorProps }
626+ tree . props = Object . assign ( { } , tree . props , selectorProps )
632627 }
633628 }
634629
@@ -672,7 +667,7 @@ export class ResponsiveCodegen {
672667 // Get pseudo-selector props (hover, active, disabled, etc.)
673668 const selectorProps = await getSelectorPropsForGroup ( componentSet , { } )
674669 if ( Object . keys ( selectorProps ) . length > 0 ) {
675- tree . props = { ... tree . props , ... selectorProps }
670+ tree . props = Object . assign ( { } , tree . props , selectorProps )
676671 }
677672
678673 // Render the tree to JSX
@@ -742,7 +737,7 @@ export class ResponsiveCodegen {
742737 perfEnd ( 'Codegen.getTree(nonViewportVariant)' , t )
743738 // Add pseudo-selector props to tree — create NEW props to avoid mutating cached tree
744739 if ( selectorProps && Object . keys ( selectorProps ) . length > 0 ) {
745- tree . props = { ... tree . props , ... selectorProps }
740+ tree . props = Object . assign ( { } , tree . props , selectorProps )
746741 }
747742 treesByVariant . set ( variantValue , tree )
748743 }
0 commit comments