Skip to content

Commit bafa937

Browse files
committed
More effective stopping of the renderer.
1 parent aea9826 commit bafa937

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

src/Components/Components/src/PublicAPI.Unshipped.txt

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ Microsoft.AspNetCore.Components.SupplyParameterFromPersistentComponentStateAttri
1212
Microsoft.Extensions.DependencyInjection.SupplyParameterFromPersistentComponentStateProviderServiceCollectionExtensions
1313
static Microsoft.AspNetCore.Components.Infrastructure.RegisterPersistentComponentStateServiceCollectionExtensions.AddPersistentServiceRegistration<TService>(Microsoft.Extensions.DependencyInjection.IServiceCollection! services, Microsoft.AspNetCore.Components.IComponentRenderMode! componentRenderMode) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
1414
static Microsoft.Extensions.DependencyInjection.SupplyParameterFromPersistentComponentStateProviderServiceCollectionExtensions.AddSupplyValueFromPersistentComponentStateProvider(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
15+
virtual Microsoft.AspNetCore.Components.RenderTree.Renderer.SignalRendererToFinishRendering() -> void

src/Components/Components/src/RenderTree/Renderer.cs

+17-2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public abstract partial class Renderer : IDisposable, IAsyncDisposable
4444
private bool _rendererIsDisposed;
4545

4646
private bool _hotReloadInitialized;
47+
private bool _rendererIsStopped;
4748

4849
/// <summary>
4950
/// Allows the caller to handle exceptions from the SynchronizationContext when one is available.
@@ -658,6 +659,12 @@ internal void AddToRenderQueue(int componentId, RenderFragment renderFragment)
658659
{
659660
Dispatcher.AssertAccess();
660661

662+
if (_rendererIsStopped)
663+
{
664+
// Once we're stopped, we'll disregard further attempts to queue anything
665+
return;
666+
}
667+
661668
var componentState = GetOptionalComponentState(componentId);
662669
if (componentState == null)
663670
{
@@ -724,14 +731,22 @@ private ComponentState GetRequiredRootComponentState(int componentId)
724731
return componentState;
725732
}
726733

734+
/// <summary>
735+
/// Stop adding render requests to the render queue.
736+
/// </summary>
737+
protected virtual void SignalRendererToFinishRendering()
738+
{
739+
_rendererIsStopped = true;
740+
}
741+
727742
/// <summary>
728743
/// Processes pending renders requests from components if there are any.
729744
/// </summary>
730745
protected virtual void ProcessPendingRender()
731746
{
732-
if (_rendererIsDisposed)
747+
if (_rendererIsDisposed || _rendererIsStopped)
733748
{
734-
// Once we're disposed, we'll disregard further attempts to render anything
749+
// Once we're disposed or stopped, we'll disregard further attempts to render anything
735750
return;
736751
}
737752

src/Components/Endpoints/src/Rendering/EndpointHtmlRenderer.cs

+2-13
Original file line numberDiff line numberDiff line change
@@ -176,21 +176,10 @@ protected override void AddPendingTask(ComponentState? componentState, Task task
176176
base.AddPendingTask(componentState, task);
177177
}
178178

179-
private void SignalRendererToFinishRendering()
179+
protected override void SignalRendererToFinishRendering()
180180
{
181181
_rendererIsStopped = true;
182-
}
183-
184-
protected override void ProcessPendingRender()
185-
{
186-
if (_rendererIsStopped)
187-
{
188-
// When the application triggers a NotFound event, we continue rendering the current batch.
189-
// However, after completing this batch, we do not want to process any further UI updates,
190-
// as we are going to return a 404 status and discard the UI updates generated so far.
191-
return;
192-
}
193-
base.ProcessPendingRender();
182+
base.SignalRendererToFinishRendering();
194183
}
195184

196185
// For tests only

0 commit comments

Comments
 (0)