@@ -24,7 +24,7 @@ public sealed partial class RazorCodeDocument
24
24
public RazorFileKind FileKind => ParserOptions . FileKind ;
25
25
26
26
private readonly PropertyTable _properties = new ( ) ;
27
- private readonly Lazy < RazorHtmlDocument > _lazyHtmlDocument ;
27
+ private readonly object _htmlDocumentLock = new ( ) ;
28
28
29
29
private RazorCodeDocument (
30
30
RazorSourceDocument source ,
@@ -40,7 +40,6 @@ private RazorCodeDocument(
40
40
CodeGenerationOptions = codeGenerationOptions ?? RazorCodeGenerationOptions . Default ;
41
41
42
42
_properties = properties ?? new ( ) ;
43
- _lazyHtmlDocument = new ( ( ) => CreateHtmlDocument ( ) ) ;
44
43
}
45
44
46
45
public static RazorCodeDocument Create (
@@ -178,17 +177,20 @@ internal void SetCSharpDocument(RazorCSharpDocument value)
178
177
}
179
178
180
179
internal RazorHtmlDocument GetHtmlDocument ( )
181
- => _lazyHtmlDocument . Value ;
182
-
183
- private RazorHtmlDocument CreateHtmlDocument ( )
184
180
{
185
181
if ( _properties . HtmlDocument . TryGetValue ( out var result ) )
186
182
{
187
183
return result ;
188
184
}
189
185
190
- result = RazorHtmlWriter . GetHtmlDocument ( this ) ;
191
- _properties . HtmlDocument . SetValue ( result ) ;
186
+ lock ( _htmlDocumentLock )
187
+ {
188
+ if ( ! _properties . HtmlDocument . TryGetValue ( out result ) )
189
+ {
190
+ result = RazorHtmlWriter . GetHtmlDocument ( this ) ;
191
+ _properties . HtmlDocument . SetValue ( result ) ;
192
+ }
193
+ }
192
194
193
195
return result ;
194
196
}
0 commit comments