@@ -10456,6 +10456,16 @@ impl<'a> TransformVisitor<'a> {
1045610456
1045710457 fn process_css_prop ( & mut self , element : & mut JSXElement ) -> Option < ( Vec < String > , Option < Expr > ) > {
1045810458 let debug_css = std:: env:: var_os ( "COMPILED_DEBUG_CSS" ) . is_some ( ) ;
10459+ if debug_css {
10460+ let element_name = match & element. opening . name {
10461+ JSXElementName :: Ident ( ident) => ident. sym . as_ref ( ) . to_string ( ) ,
10462+ _ => "<complex>" . to_string ( ) ,
10463+ } ;
10464+ eprintln ! (
10465+ "[compiled-debug] process_css_prop called for <{}>" ,
10466+ element_name
10467+ ) ;
10468+ }
1045910469 let mut css_index = None ;
1046010470 let mut class_index = None ;
1046110471 let mut key_expr: Option < Expr > = None ;
@@ -10588,9 +10598,32 @@ impl<'a> TransformVisitor<'a> {
1058810598 } else if let Some ( expr) = & original_css_expr {
1058910599 if let Expr :: Ident ( ident) = expr {
1059010600 self . mark_css_binding_used ( ident) ;
10591- match self . css_runtime_artifacts . get ( & to_id ( ident) ) . cloned ( ) {
10601+ let ident_id = to_id ( ident) ;
10602+ if std:: env:: var_os ( "COMPILED_DEBUG_CSS" ) . is_some ( ) {
10603+ eprintln ! (
10604+ "[compiled-debug] process_css_prop looking up artifacts for ident: {}" ,
10605+ ident. sym
10606+ ) ;
10607+ eprintln ! (
10608+ "[compiled-debug] css_runtime_artifacts keys: {:?}" ,
10609+ self
10610+ . css_runtime_artifacts
10611+ . keys( )
10612+ . map( |( sym, _) | sym. to_string( ) )
10613+ . collect:: <Vec <_>>( )
10614+ ) ;
10615+ }
10616+ match self . css_runtime_artifacts . get ( & ident_id) . cloned ( ) {
1059210617 Some ( artifacts) => artifacts,
10593- None => return None ,
10618+ None => {
10619+ if std:: env:: var_os ( "COMPILED_DEBUG_CSS" ) . is_some ( ) {
10620+ eprintln ! (
10621+ "[compiled-debug] process_css_prop artifact not found for: {}" ,
10622+ ident. sym
10623+ ) ;
10624+ }
10625+ return None ;
10626+ }
1059410627 }
1059510628 } else {
1059610629 using_runtime_artifacts = true ;
@@ -11413,7 +11446,10 @@ impl<'a> VisitMut for TransformVisitor<'a> {
1141311446 JSXElementName :: Ident ( ident) => ident. sym . as_ref ( ) . to_string ( ) ,
1141411447 _ => "<complex>" . to_string ( ) ,
1141511448 } ;
11416- eprintln ! ( "[compiled-debug] visit JSXElement name={}" , element_name) ;
11449+ eprintln ! (
11450+ "[compiled-debug] visit_mut_expr JSXElement name={}" ,
11451+ element_name
11452+ ) ;
1141711453 }
1141811454 if let Some ( mut replacement) = self . handle_class_names_element ( element) {
1141911455 replacement. visit_mut_with ( self ) ;
@@ -12079,17 +12115,67 @@ impl<'a> VisitMut for TransformVisitor<'a> {
1207912115 }
1208012116
1208112117 fn visit_mut_jsx_element ( & mut self , element : & mut JSXElement ) {
12118+ if std:: env:: var_os ( "COMPILED_DEBUG_CSS" ) . is_some ( ) {
12119+ let element_name = match & element. opening . name {
12120+ JSXElementName :: Ident ( ident) => ident. sym . as_ref ( ) . to_string ( ) ,
12121+ _ => "<complex>" . to_string ( ) ,
12122+ } ;
12123+ eprintln ! ( "[compiled-debug] visit_mut_jsx_element <{}>" , element_name) ;
12124+ }
12125+
12126+ // Process the css={} prop
12127+ let css_info = self . process_css_prop ( element) ;
12128+
12129+ // Walk children
12130+ element. visit_mut_children_with ( self ) ;
12131+ self . walk_jsx_children ( element) ;
12132+
12133+ // Handle xcss attributes and runtime sheets
12134+ let mut runtime_sheets: Vec < String > = Vec :: new ( ) ;
12135+ let mut key_expr: Option < Expr > = None ;
12136+ let mut xcss_transformed = false ;
12137+
12138+ if let Some ( ( sheets, key) ) = css_info {
12139+ if !self . options . extract && !sheets. is_empty ( ) {
12140+ runtime_sheets. extend ( sheets) ;
12141+ }
12142+ key_expr = key;
12143+ if std:: env:: var_os ( "COMPILED_DEBUG_CSS" ) . is_some ( ) {
12144+ eprintln ! (
12145+ "[compiled-debug] visit_mut_jsx_element css_info runtime_sheets={} key_set={}" ,
12146+ runtime_sheets. len( ) ,
12147+ key_expr. is_some( )
12148+ ) ;
12149+ }
12150+ }
12151+
1208212152 if self . options . extract {
1208312153 if let Some ( result) = self . process_xcss_attributes ( element) {
12154+ if !result. runtime_sheets . is_empty ( ) {
12155+ runtime_sheets. extend ( result. runtime_sheets ) ;
12156+ }
1208412157 if !result. pending_class_names . is_empty ( ) {
1208512158 let mut resolved = self . resolve_pending_xcss ( & result. pending_class_names ) ;
12086- if std:: env:: var_os ( "COMPILED_DEBUG_CSS" ) . is_some ( ) && resolved. is_empty ( ) {
12087- eprintln ! ( "[compiled-debug] resolve_pending_xcss produced no sheets" ) ;
12088- }
12159+ runtime_sheets. append ( & mut resolved) ;
12160+ }
12161+ if result. transformed || !result. pending_class_names . is_empty ( ) {
12162+ xcss_transformed = true ;
1208912163 }
1209012164 }
1209112165 }
12092- self . walk_jsx_children ( element) ;
12166+
12167+ if !runtime_sheets. is_empty ( ) {
12168+ if !self . options . extract {
12169+ self . needs_runtime_ax = true ;
12170+ }
12171+ let inner = element. clone ( ) ;
12172+ let wrapper =
12173+ self . build_runtime_component ( Expr :: JSXElement ( Box :: new ( inner) ) , runtime_sheets, key_expr) ;
12174+ // Note: We cannot directly replace the element here. The element is being processed in-place.
12175+ // The wrapper would need to be created at a higher level in visit_mut_expr.
12176+ } else if xcss_transformed {
12177+ // Metadata registrations have already occurred; no runtime wrapper required.
12178+ }
1209312179 }
1209412180}
1209512181
0 commit comments