File tree Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -67,6 +67,14 @@ export class StyleInjector {
6767 if ( generatedClass && registry . rules . has ( generatedClass ) ) {
6868 const currentRefCount = registry . refCounts . get ( generatedClass ) || 0 ;
6969 registry . refCounts . set ( generatedClass , currentRefCount + 1 ) ;
70+ // If this class was previously marked as unused, clear that state now
71+ if ( registry . unusedRules . has ( generatedClass ) ) {
72+ registry . unusedRules . delete ( generatedClass ) ;
73+ if ( registry . metrics ) {
74+ // Consider this a reuse rather than a cold miss
75+ registry . metrics . unusedHits ++ ;
76+ }
77+ }
7078
7179 // Update metrics
7280 if ( registry . metrics ) {
Original file line number Diff line number Diff line change @@ -575,6 +575,25 @@ export class SheetManager {
575575 rulesInSheet . sort ( ( a , b ) => b . ruleInfo . ruleIndex - a . ruleInfo . ruleIndex ) ;
576576
577577 for ( const { className, ruleInfo } of rulesInSheet ) {
578+ // SAFETY: Re-check that the rule is still unused at deletion time.
579+ // Between scheduling and execution a class may have been restored
580+ // (refCounts set and removed from unusedRules). Skip such entries.
581+ if ( ! registry . unusedRules . has ( className ) ) {
582+ continue ;
583+ }
584+ if ( registry . refCounts . has ( className ) ) {
585+ // Class became active again; do not delete
586+ continue ;
587+ }
588+
589+ // Ensure we delete the same RuleInfo we marked earlier to avoid
590+ // accidentally deleting updated rules for the same class.
591+ const currentInfo = registry . rules . get ( className ) ;
592+ if ( currentInfo && currentInfo !== ruleInfo ) {
593+ // Rule was replaced; skip deletion of the old reference
594+ continue ;
595+ }
596+
578597 this . deleteRule ( registry , ruleInfo ) ;
579598 registry . rules . delete ( className ) ;
580599 registry . unusedRules . delete ( className ) ;
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ const MAP = {
2727 'border' ,
2828 'border-radius' ,
2929 'outline' ,
30+ 'opacity' ,
3031 ] ,
3132 inset : [ 'box-shadow' ] ,
3233 mark : [ 'box-shadow' ] ,
You can’t perform that action at this time.
0 commit comments