diff --git a/src/Components/Web/src/HtmlRendering/StaticHtmlRenderer.HtmlWriting.cs b/src/Components/Web/src/HtmlRendering/StaticHtmlRenderer.HtmlWriting.cs
index 634b6a100f5b..9cbc12e2aecd 100644
--- a/src/Components/Web/src/HtmlRendering/StaticHtmlRenderer.HtmlWriting.cs
+++ b/src/Components/Web/src/HtmlRendering/StaticHtmlRenderer.HtmlWriting.cs
@@ -21,8 +21,8 @@ public partial class StaticHtmlRenderer
string.Empty,
typeof(FormMappingContext));
- private static readonly TextEncoder _javaScriptEncoder = JavaScriptEncoder.Default;
- private TextEncoder _htmlEncoder = HtmlEncoder.Default;
+ private readonly TextEncoder _javaScriptEncoder;
+ private TextEncoder _htmlEncoder;
private string? _closestSelectValueAsString;
///
diff --git a/src/Components/Web/src/HtmlRendering/StaticHtmlRenderer.cs b/src/Components/Web/src/HtmlRendering/StaticHtmlRenderer.cs
index ad6cd29a32af..28cc2d3e9e69 100644
--- a/src/Components/Web/src/HtmlRendering/StaticHtmlRenderer.cs
+++ b/src/Components/Web/src/HtmlRendering/StaticHtmlRenderer.cs
@@ -3,6 +3,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Runtime.ExceptionServices;
+using System.Text.Encodings.Web;
using Microsoft.AspNetCore.Components.RenderTree;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.Web.HtmlRendering;
@@ -30,6 +31,8 @@ public StaticHtmlRenderer(IServiceProvider serviceProvider, ILoggerFactory logge
: base(serviceProvider, loggerFactory)
{
_navigationManager = serviceProvider.GetService();
+ _htmlEncoder = serviceProvider.GetService() ?? HtmlEncoder.Default;
+ _javaScriptEncoder = serviceProvider.GetService() ?? JavaScriptEncoder.Default;
}
///