Skip to content

Commit 06468ee

Browse files
committed
PR feedback
1 parent bd88966 commit 06468ee

File tree

9 files changed

+13
-17
lines changed

9 files changed

+13
-17
lines changed

src/Components/Components/src/Rendering/HtmlRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public HtmlRenderer(IServiceProvider serviceProvider, ILoggerFactory loggerFacto
3636
_htmlEncoder = htmlEncoder;
3737
}
3838

39-
public override Dispatcher Dispatcher { get; } = new RendererSynchronizationContextDispatcher();
39+
public override Dispatcher Dispatcher { get; } = Dispatcher.CreateDefault();
4040

4141
/// <inheritdoc />
4242
protected override Task UpdateDisplayAsync(in RenderBatch renderBatch)

src/Components/Components/src/Rendering/Renderer.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -375,17 +375,16 @@ private int FindLatestEventHandlerIdInChain(int eventHandlerId)
375375

376376
private void EnsureSynchronizationContext()
377377
{
378-
// When the Dispatcher is a synchronization context
379-
// Render operations are not thread-safe, so they need to be serialized.
378+
// Render operations are not thread-safe, so they need to be serialized by the dispatcher.
380379
// Plus, any other logic that mutates state accessed during rendering also
381380
// needs not to run concurrently with rendering so should be dispatched to
382381
// the renderer's sync context.
383382
if (!Dispatcher.CheckAccess())
384383
{
385384
throw new InvalidOperationException(
386-
"The current thread is not associated with the renderer's synchronization context. " +
387-
"Use Invoke() or InvokeAsync() to switch execution to the renderer's synchronization " +
388-
"context when triggering rendering or modifying any state accessed during rendering.");
385+
"The current thread is not associated with the Dispatcher. " +
386+
"Use Invoke() or InvokeAsync() to switch execution to the Dispatcher when " +
387+
"triggering rendering or modifying any state accessed during rendering.");
389388
}
390389
}
391390

src/Components/Components/test/RenderTreeBuilderTest.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,10 +1797,9 @@ private class TestRenderer : Renderer
17971797
{
17981798
public TestRenderer() : base(new TestServiceProvider(), NullLoggerFactory.Instance)
17991799
{
1800-
Dispatcher = new RendererSynchronizationContextDispatcher();
18011800
}
18021801

1803-
public override Dispatcher Dispatcher { get; }
1802+
public override Dispatcher Dispatcher { get; } = Dispatcher.CreateDefault();
18041803

18051804
protected override void HandleException(Exception exception)
18061805
=> throw new NotImplementedException();

src/Components/Server/src/Circuits/CircuitHost.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,9 @@ public CircuitHost(
9494

9595
public IServiceProvider Services { get; }
9696

97-
public Dispatcher Dispatcher { get; }
98-
9997
public Task<ComponentRenderedText> PrerenderComponentAsync(Type componentType, ParameterCollection parameters)
10098
{
101-
return Dispatcher.InvokeAsync(async () =>
99+
return Renderer.Dispatcher.InvokeAsync(async () =>
102100
{
103101
var result = await Renderer.RenderComponentAsync(componentType, parameters);
104102

src/Components/Server/src/Circuits/CircuitRegistry.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public virtual Task DisconnectAsync(CircuitHost circuitHost, string connectionId
9090
{
9191
if (DisconnectCore(circuitHost, connectionId))
9292
{
93-
circuitHandlerTask = circuitHost.Dispatcher.InvokeAsync(() => circuitHost.OnConnectionDownAsync(default));
93+
circuitHandlerTask = circuitHost.Renderer.Dispatcher.InvokeAsync(() => circuitHost.OnConnectionDownAsync(default));
9494
}
9595
else
9696
{
@@ -189,7 +189,7 @@ public virtual async Task<CircuitHost> ConnectAsync(string circuitId, IClientPro
189189

190190
// Dispatch the circuit handlers inside the sync context to ensure the order of execution. CircuitHost executes circuit handlers inside of
191191
//
192-
circuitHandlerTask = circuitHost.Dispatcher.InvokeAsync(async () =>
192+
circuitHandlerTask = circuitHost.Renderer.Dispatcher.InvokeAsync(async () =>
193193
{
194194
if (previouslyConnected)
195195
{

src/Components/Server/test/Circuits/CircuitHostTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public async Task DisposeAsync_DisposesRendererWithinSynchronizationContext()
8282
serviceScope.Object,
8383
remoteRenderer);
8484

85-
var component = new DispatcherComponent(circuitHost.Dispatcher);
85+
var component = new DispatcherComponent(circuitHost.Renderer.Dispatcher);
8686
circuitHost.Renderer.AssignRootComponentId(component);
8787
var original = SynchronizationContext.Current;
8888
SynchronizationContext.SetSynchronizationContext(null);

src/Components/Shared/test/TestRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public TestRenderer(Dispatcher dispatcher) : base(new TestServiceProvider(), Nul
2525

2626
public TestRenderer(IServiceProvider serviceProvider) : base(serviceProvider, NullLoggerFactory.Instance)
2727
{
28-
Dispatcher = new RendererSynchronizationContextDispatcher();
28+
Dispatcher = Dispatcher.CreateDefault();
2929
}
3030

3131
public override Dispatcher Dispatcher { get; }

src/Components/test/E2ETest/ServerExecutionTests/ServerComponentRenderingTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void ThrowsIfRenderIsRequestedOutsideSyncContext()
3333
appElement.FindElement(By.Id("run-without-dispatch")).Click();
3434

3535
Browser.Contains(
36-
$"{typeof(InvalidOperationException).FullName}: The current thread is not associated with the renderer's synchronization context",
36+
$"{typeof(InvalidOperationException).FullName}: The current thread is not associated with the Dispatcher. Use Invoke() or InvokeAsync() to switch execution to the Dispatcher when triggering rendering or modifying any state accessed during rendering.",
3737
() => result.Text);
3838
}
3939
}

src/Components/test/Ignitor.Test/RenderBatchReaderTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ public FakeRenderer()
339339
{
340340
}
341341

342-
public override Dispatcher Dispatcher { get; } = new RendererSynchronizationContextDispatcher();
342+
public override Dispatcher Dispatcher { get; } = Dispatcher.CreateDefault();
343343

344344
protected override void HandleException(Exception exception)
345345
{

0 commit comments

Comments
 (0)