@@ -14,7 +14,7 @@ internal class StyledImpl : IStyled
14
14
private readonly int _priority ;
15
15
private readonly Cache _cache ;
16
16
17
- public StyledImpl ( ScriptManager scriptManager , Cache cache ) : this ( scriptManager , cache , DEFAULT , 100_000 )
17
+ public StyledImpl ( ScriptManager scriptManager , Cache cache ) : this ( scriptManager , cache , DEFAULT , 100_000 )
18
18
{
19
19
20
20
}
@@ -32,28 +32,34 @@ public async Task<string> CssAsync(string className, string css)
32
32
try
33
33
{
34
34
string preParseHash = css . GetStableHashCodeString ( ) ;
35
- if ( ! _cache . Seen . ContainsKey ( preParseHash ) )
35
+ if ( ! _cache . Seen . ContainsKey ( preParseHash ) )
36
36
{
37
37
css = css . RemoveComments ( ) . RemoveDuplicateSpaces ( ) ;
38
38
IList < ParsedClass > parsedClasses = css . GetClasses ( className ) ;
39
39
if ( parsedClasses . Count > 0 )
40
40
{
41
41
string hash = parsedClasses . First ( ) . IsMediaQuery ? parsedClasses . First ( ) . ChildClasses . First ( ) . Name . Replace ( "." , string . Empty ) : parsedClasses . First ( ) . Name ;
42
42
await _scriptManager . UpdatedParsedClasses ( _id . GetStableHashCodeString ( ) , _id , _priority , parsedClasses ) ;
43
- _cache . Seen . Add ( preParseHash , hash ) ;
43
+ if ( ! _cache . Seen . ContainsKey ( preParseHash ) )
44
+ {
45
+ _cache . Seen . Add ( preParseHash , hash ) ;
46
+ }
44
47
return hash ;
45
48
}
46
49
else
47
50
{
48
- _cache . Seen . Add ( preParseHash , string . Empty ) ;
51
+ if ( ! _cache . Seen . ContainsKey ( preParseHash ) )
52
+ {
53
+ _cache . Seen . Add ( preParseHash , string . Empty ) ;
54
+ }
49
55
return string . Empty ;
50
56
}
51
- }
57
+ }
52
58
else
53
59
{
54
60
return _cache . Seen [ preParseHash ] ;
55
61
}
56
-
62
+
57
63
}
58
64
catch ( StyledException e )
59
65
{
@@ -94,12 +100,18 @@ public string Css(string className, string css)
94
100
{
95
101
string hash = parsedClasses . First ( ) . IsMediaQuery ? parsedClasses . First ( ) . ChildClasses . First ( ) . Name . Replace ( "." , string . Empty ) : parsedClasses . First ( ) . Name ;
96
102
Task . Run ( ( ) => _scriptManager . UpdatedParsedClasses ( _id . GetStableHashCodeString ( ) , _id , _priority , parsedClasses ) ) ;
97
- _cache . Seen . Add ( preParseHash , hash ) ;
103
+ if ( ! _cache . Seen . ContainsKey ( preParseHash ) )
104
+ {
105
+ _cache . Seen . Add ( preParseHash , hash ) ;
106
+ }
98
107
return hash ;
99
108
}
100
109
else
101
110
{
102
- _cache . Seen . Add ( preParseHash , string . Empty ) ;
111
+ if ( ! _cache . Seen . ContainsKey ( preParseHash ) )
112
+ {
113
+ _cache . Seen . Add ( preParseHash , string . Empty ) ;
114
+ }
103
115
return string . Empty ;
104
116
}
105
117
}
@@ -144,7 +156,10 @@ public async Task<string> KeyframesAsync(string css)
144
156
css = "@keyframes &{" + css . RemoveComments ( ) . RemoveDuplicateSpaces ( ) + "}" ;
145
157
IList < ParsedClass > parsedClasses = css . GetClasses ( ) ;
146
158
await _scriptManager . UpdatedParsedClasses ( _id . GetStableHashCodeString ( ) , _id , _priority , parsedClasses ) ;
147
- _cache . Seen . Add ( preParseHash , parsedClasses . First ( ) . Hash ) ;
159
+ if ( ! _cache . Seen . ContainsKey ( preParseHash ) )
160
+ {
161
+ _cache . Seen . Add ( preParseHash , parsedClasses . First ( ) . Hash ) ;
162
+ }
148
163
return parsedClasses . First ( ) . Hash ;
149
164
}
150
165
else
@@ -172,7 +187,10 @@ public string Keyframes(string css)
172
187
css = "@keyframes &{" + css . RemoveComments ( ) . RemoveDuplicateSpaces ( ) + "}" ;
173
188
IList < ParsedClass > parsedClasses = css . GetClasses ( ) ;
174
189
Task . Run ( ( ) => _scriptManager . UpdatedParsedClasses ( _id . GetStableHashCodeString ( ) , _id , _priority , parsedClasses ) ) ;
175
- _cache . Seen . Add ( preParseHash , parsedClasses . First ( ) . Hash ) ;
190
+ if ( ! _cache . Seen . ContainsKey ( preParseHash ) )
191
+ {
192
+ _cache . Seen . Add ( preParseHash , parsedClasses . First ( ) . Hash ) ;
193
+ }
176
194
return parsedClasses . First ( ) . Hash ;
177
195
}
178
196
else
0 commit comments