Skip to content

Commit a3a482b

Browse files
author
Ryan Nowak
committed
Remove stateful prerendering
Fixes: #12245 Fixes: #12630 This change removes stateful pre-rendering from Server-Side Blazor. This means that when you render a component during the initial HTTP request, we we will no longer preserve the component instances and their parameters. While this feature was useful, it cause serious scalability concerns. This means that it will now be required to register "entry-point" components in startup similar to client-side Blazor.
1 parent 5619385 commit a3a482b

File tree

52 files changed

+86
-1851
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+86
-1851
lines changed

Diff for: eng/ProjectReferences.props

-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@
101101
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Razor" ProjectPath="$(RepoRoot)src\Razor\Razor\src\Microsoft.AspNetCore.Razor.csproj" RefProjectPath="$(RepoRoot)src\Razor\Razor\ref\Microsoft.AspNetCore.Razor.csproj" />
102102
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Mvc.Abstractions" ProjectPath="$(RepoRoot)src\Mvc\Mvc.Abstractions\src\Microsoft.AspNetCore.Mvc.Abstractions.csproj" RefProjectPath="$(RepoRoot)src\Mvc\Mvc.Abstractions\ref\Microsoft.AspNetCore.Mvc.Abstractions.csproj" />
103103
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Mvc.ApiExplorer" ProjectPath="$(RepoRoot)src\Mvc\Mvc.ApiExplorer\src\Microsoft.AspNetCore.Mvc.ApiExplorer.csproj" RefProjectPath="$(RepoRoot)src\Mvc\Mvc.ApiExplorer\ref\Microsoft.AspNetCore.Mvc.ApiExplorer.csproj" />
104-
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Mvc.Components.Prerendering" ProjectPath="$(RepoRoot)src\Mvc\Mvc.Components.Prerendering\src\Microsoft.AspNetCore.Mvc.Components.Prerendering.csproj" RefProjectPath="$(RepoRoot)src\Mvc\Mvc.Components.Prerendering\ref\Microsoft.AspNetCore.Mvc.Components.Prerendering.csproj" />
105104
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Mvc.Core" ProjectPath="$(RepoRoot)src\Mvc\Mvc.Core\src\Microsoft.AspNetCore.Mvc.Core.csproj" RefProjectPath="$(RepoRoot)src\Mvc\Mvc.Core\ref\Microsoft.AspNetCore.Mvc.Core.csproj" />
106105
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Mvc.Cors" ProjectPath="$(RepoRoot)src\Mvc\Mvc.Cors\src\Microsoft.AspNetCore.Mvc.Cors.csproj" RefProjectPath="$(RepoRoot)src\Mvc\Mvc.Cors\ref\Microsoft.AspNetCore.Mvc.Cors.csproj" />
107106
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Mvc.DataAnnotations" ProjectPath="$(RepoRoot)src\Mvc\Mvc.DataAnnotations\src\Microsoft.AspNetCore.Mvc.DataAnnotations.csproj" RefProjectPath="$(RepoRoot)src\Mvc\Mvc.DataAnnotations\ref\Microsoft.AspNetCore.Mvc.DataAnnotations.csproj" />

Diff for: eng/SharedFramework.Local.props

-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
<AspNetCoreAppReference Include="Microsoft.AspNetCore.Razor" />
7474
<AspNetCoreAppReference Include="Microsoft.AspNetCore.Mvc.Abstractions" />
7575
<AspNetCoreAppReference Include="Microsoft.AspNetCore.Mvc.ApiExplorer" />
76-
<AspNetCoreAppReference Include="Microsoft.AspNetCore.Mvc.Components.Prerendering" />
7776
<AspNetCoreAppReference Include="Microsoft.AspNetCore.Mvc.Core" />
7877
<AspNetCoreAppReference Include="Microsoft.AspNetCore.Mvc.Cors" />
7978
<AspNetCoreAppReference Include="Microsoft.AspNetCore.Mvc.DataAnnotations" />

Diff for: src/Components/Components.sln

-15
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
208208
..\..\.editorconfig = ..\..\.editorconfig
209209
EndProjectSection
210210
EndProject
211-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Mvc.Components.Prerendering", "..\Mvc\Mvc.Components.Prerendering\src\Microsoft.AspNetCore.Mvc.Components.Prerendering.csproj", "{3A4132B6-60DA-43A0-8E7B-4BF346F3247C}"
212-
EndProject
213211
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.SignalR.Protocols.Json", "..\SignalR\common\Protocols.Json\src\Microsoft.AspNetCore.SignalR.Protocols.Json.csproj", "{ED210157-461B-45BB-9D86-B81A62792C30}"
214212
EndProject
215213
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.SignalR.Client", "..\SignalR\clients\csharp\Client\src\Microsoft.AspNetCore.SignalR.Client.csproj", "{DA137BD4-F7F1-4D53-855F-5EC40CEA36B0}"
@@ -1330,18 +1328,6 @@ Global
13301328
{9088E4E4-B855-457F-AE9E-D86709A5E1F4}.Release|x64.Build.0 = Debug|Any CPU
13311329
{9088E4E4-B855-457F-AE9E-D86709A5E1F4}.Release|x86.ActiveCfg = Debug|Any CPU
13321330
{9088E4E4-B855-457F-AE9E-D86709A5E1F4}.Release|x86.Build.0 = Debug|Any CPU
1333-
{3A4132B6-60DA-43A0-8E7B-4BF346F3247C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1334-
{3A4132B6-60DA-43A0-8E7B-4BF346F3247C}.Debug|Any CPU.Build.0 = Debug|Any CPU
1335-
{3A4132B6-60DA-43A0-8E7B-4BF346F3247C}.Debug|x64.ActiveCfg = Debug|Any CPU
1336-
{3A4132B6-60DA-43A0-8E7B-4BF346F3247C}.Debug|x64.Build.0 = Debug|Any CPU
1337-
{3A4132B6-60DA-43A0-8E7B-4BF346F3247C}.Debug|x86.ActiveCfg = Debug|Any CPU
1338-
{3A4132B6-60DA-43A0-8E7B-4BF346F3247C}.Debug|x86.Build.0 = Debug|Any CPU
1339-
{3A4132B6-60DA-43A0-8E7B-4BF346F3247C}.Release|Any CPU.ActiveCfg = Release|Any CPU
1340-
{3A4132B6-60DA-43A0-8E7B-4BF346F3247C}.Release|Any CPU.Build.0 = Release|Any CPU
1341-
{3A4132B6-60DA-43A0-8E7B-4BF346F3247C}.Release|x64.ActiveCfg = Release|Any CPU
1342-
{3A4132B6-60DA-43A0-8E7B-4BF346F3247C}.Release|x64.Build.0 = Release|Any CPU
1343-
{3A4132B6-60DA-43A0-8E7B-4BF346F3247C}.Release|x86.ActiveCfg = Release|Any CPU
1344-
{3A4132B6-60DA-43A0-8E7B-4BF346F3247C}.Release|x86.Build.0 = Release|Any CPU
13451331
{ED210157-461B-45BB-9D86-B81A62792C30}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
13461332
{ED210157-461B-45BB-9D86-B81A62792C30}.Debug|Any CPU.Build.0 = Debug|Any CPU
13471333
{ED210157-461B-45BB-9D86-B81A62792C30}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -1548,7 +1534,6 @@ Global
15481534
{04262990-929C-42BF-85A9-21C25FA95617} = {2FC10057-7A0A-4E34-8302-879925BC0102}
15491535
{DC47C40A-FC38-44E4-94A4-ADE794E76309} = {2FC10057-7A0A-4E34-8302-879925BC0102}
15501536
{9088E4E4-B855-457F-AE9E-D86709A5E1F4} = {7260DED9-22A9-4E9D-92F4-5E8A4404DEAF}
1551-
{3A4132B6-60DA-43A0-8E7B-4BF346F3247C} = {2FC10057-7A0A-4E34-8302-879925BC0102}
15521537
{ED210157-461B-45BB-9D86-B81A62792C30} = {2FC10057-7A0A-4E34-8302-879925BC0102}
15531538
{DA137BD4-F7F1-4D53-855F-5EC40CEA36B0} = {2FC10057-7A0A-4E34-8302-879925BC0102}
15541539
{0CDAB70B-71DC-43BE-ACB7-AD2EE3541FFB} = {2FC10057-7A0A-4E34-8302-879925BC0102}

Diff for: src/Components/Server/ref/Microsoft.AspNetCore.Components.Server.netcoreapp3.0.cs

-18
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ public static partial class ComponentEndpointConventionBuilderExtensions
1414
}
1515
public static partial class ComponentEndpointRouteBuilderExtensions
1616
{
17-
public static Microsoft.AspNetCore.Builder.ComponentEndpointConventionBuilder MapBlazorHub(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints) { throw null; }
18-
public static Microsoft.AspNetCore.Builder.ComponentEndpointConventionBuilder MapBlazorHub(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, System.Action<Microsoft.AspNetCore.Http.Connections.HttpConnectionDispatcherOptions> configureOptions) { throw null; }
1917
public static Microsoft.AspNetCore.Builder.ComponentEndpointConventionBuilder MapBlazorHub(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, System.Type type, string selector) { throw null; }
2018
public static Microsoft.AspNetCore.Builder.ComponentEndpointConventionBuilder MapBlazorHub(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, System.Type type, string selector, System.Action<Microsoft.AspNetCore.Http.Connections.HttpConnectionDispatcherOptions> configureOptions) { throw null; }
2119
public static Microsoft.AspNetCore.Builder.ComponentEndpointConventionBuilder MapBlazorHub(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, System.Type componentType, string selector, string path) { throw null; }
@@ -36,22 +34,6 @@ public CircuitOptions() { }
3634
public System.TimeSpan DisconnectedCircuitRetentionPeriod { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
3735
public System.TimeSpan JSInteropDefaultCallTimeout { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
3836
}
39-
public partial class ComponentPrerenderingContext
40-
{
41-
public ComponentPrerenderingContext() { }
42-
public System.Type ComponentType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
43-
public Microsoft.AspNetCore.Http.HttpContext Context { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
44-
public Microsoft.AspNetCore.Components.ParameterView Parameters { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
45-
}
46-
public sealed partial class ComponentPrerenderResult
47-
{
48-
internal ComponentPrerenderResult() { }
49-
public void WriteTo(System.IO.TextWriter writer) { }
50-
}
51-
public partial interface IComponentPrerenderer
52-
{
53-
System.Threading.Tasks.Task<Microsoft.AspNetCore.Components.Server.ComponentPrerenderResult> PrerenderComponentAsync(Microsoft.AspNetCore.Components.Server.ComponentPrerenderingContext context);
54-
}
5537
}
5638
namespace Microsoft.AspNetCore.Components.Server.Circuits
5739
{

Diff for: src/Components/Server/src/Builder/ComponentEndpointRouteBuilderExtensions.cs

-36
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,6 @@ namespace Microsoft.AspNetCore.Builder
1515
/// </summary>
1616
public static class ComponentEndpointRouteBuilderExtensions
1717
{
18-
/// <summary>
19-
/// Maps the Blazor <see cref="Hub" /> to the default path.
20-
/// </summary>
21-
/// <param name="endpoints">The <see cref="IEndpointRouteBuilder"/>.</param>
22-
/// <returns>The <see cref="ComponentEndpointConventionBuilder"/>.</returns>
23-
public static ComponentEndpointConventionBuilder MapBlazorHub(this IEndpointRouteBuilder endpoints)
24-
{
25-
if (endpoints == null)
26-
{
27-
throw new ArgumentNullException(nameof(endpoints));
28-
}
29-
30-
return endpoints.MapBlazorHub(configureOptions: _ => { });
31-
}
32-
33-
/// <summary>
34-
/// Maps the Blazor <see cref="Hub" /> to the default path.
35-
/// </summary>
36-
/// <param name="endpoints">The <see cref="IEndpointRouteBuilder"/>.</param>
37-
/// <param name="configureOptions">A callback to configure dispatcher options.</param>
38-
/// <returns>The <see cref="ComponentEndpointConventionBuilder"/>.</returns>
39-
public static ComponentEndpointConventionBuilder MapBlazorHub(this IEndpointRouteBuilder endpoints, Action<HttpConnectionDispatcherOptions> configureOptions)
40-
{
41-
if (endpoints == null)
42-
{
43-
throw new ArgumentNullException(nameof(endpoints));
44-
}
45-
46-
if (configureOptions == null)
47-
{
48-
throw new ArgumentNullException(nameof(configureOptions));
49-
}
50-
51-
return new ComponentEndpointConventionBuilder(endpoints.MapHub<ComponentHub>(ComponentHub.DefaultPath, configureOptions));
52-
}
53-
5418
/// <summary>
5519
///Maps the Blazor <see cref="Hub" /> to the default path and associates
5620
/// the component <typeparamref name="TComponent"/> to this hub instance as the given DOM <paramref name="selector"/>.

Diff for: src/Components/Server/src/Circuits/CircuitHost.cs

+4-39
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
using System.Text.Json;
88
using System.Threading;
99
using System.Threading.Tasks;
10-
using Microsoft.AspNetCore.Components.Rendering;
11-
using Microsoft.AspNetCore.Components.Routing;
1210
using Microsoft.AspNetCore.Components.Web;
1311
using Microsoft.AspNetCore.Components.Web.Rendering;
1412
using Microsoft.Extensions.DependencyInjection;
@@ -57,7 +55,7 @@ public CircuitHost(
5755
CircuitClientProxy client,
5856
RendererRegistry rendererRegistry,
5957
RemoteRenderer renderer,
60-
IList<ComponentDescriptor> descriptors,
58+
IReadOnlyList<ComponentDescriptor> descriptors,
6159
RemoteJSRuntime jsRuntime,
6260
CircuitHandler[] circuitHandlers,
6361
ILogger logger)
@@ -92,24 +90,10 @@ public CircuitHost(
9290

9391
public RendererRegistry RendererRegistry { get; }
9492

95-
public IList<ComponentDescriptor> Descriptors { get; }
93+
public IReadOnlyList<ComponentDescriptor> Descriptors { get; }
9694

9795
public IServiceProvider Services { get; }
9896

99-
public Task<ComponentRenderedText> PrerenderComponentAsync(Type componentType, ParameterView parameters)
100-
{
101-
return Renderer.Dispatcher.InvokeAsync(async () =>
102-
{
103-
var result = await Renderer.RenderComponentAsync(componentType, parameters);
104-
105-
// When we prerender we start the circuit in a disconnected state. As such, we only call
106-
// OnCircuitOpenenedAsync here and when the client reconnects we run OnConnectionUpAsync
107-
await OnCircuitOpenedAsync(CancellationToken.None);
108-
109-
return result;
110-
});
111-
}
112-
11397
public void SetCircuitUser(ClaimsPrincipal user)
11498
{
11599
var authenticationStateProvider = Services.GetService<AuthenticationStateProvider>() as IHostEnvironmentAuthenticationStateProvider;
@@ -120,26 +104,6 @@ public void SetCircuitUser(ClaimsPrincipal user)
120104
}
121105
}
122106

123-
internal void InitializeCircuitAfterPrerender(UnhandledExceptionEventHandler unhandledException)
124-
{
125-
if (!_initialized)
126-
{
127-
_initialized = true;
128-
UnhandledException += unhandledException;
129-
var uriHelper = (RemoteUriHelper)Services.GetRequiredService<IUriHelper>();
130-
if (!uriHelper.HasAttachedJSRuntime)
131-
{
132-
uriHelper.AttachJsRuntime(JSRuntime);
133-
}
134-
135-
var navigationInterception = (RemoteNavigationInterception)Services.GetRequiredService<INavigationInterception>();
136-
if (!navigationInterception.HasAttachedJSRuntime)
137-
{
138-
navigationInterception.AttachJSRuntime(JSRuntime);
139-
}
140-
}
141-
}
142-
143107
internal void SendPendingBatches()
144108
{
145109
// Dispatch any buffered renders we accumulated during a disconnect.
@@ -233,7 +197,8 @@ await Renderer.Dispatcher.InvokeAsync(async () =>
233197
// That's because AddComponentAsync waits for quiescence, which can take
234198
// arbitrarily long. In the meantime we might need to be receiving and
235199
// processing incoming JSInterop calls or similar.
236-
for (var i = 0; i < Descriptors.Count; i++)
200+
var count = Descriptors.Count;
201+
for (var i = 0; i < count; i++)
237202
{
238203
var (componentType, domElementSelector, prerendered) = Descriptors[i];
239204
if (!prerendered)

0 commit comments

Comments
 (0)