Skip to content

Commit 2d9cba8

Browse files
javiercnmkArtakMSFT
authored andcommitted
[Components] Prerrendering startup experience (#7770)
[Components] Prerrendering startup experience * Introduces an IComponentPrerrenderer to handle Prerrendering * MVC registers a basic static prerrrenderer. * Components registers a more feature complete prerrender that will handle reconnection to the original circuit after prerrendering in the future to allow for prerrendered interactive components. * Removes UseRazorComponents * Removes the SPA fallback in favor of a catch all route in Index.cshtml * Moves the framework files to be served by the default StaticFiles middleware in the pipeline by way of plugging specific providers through options. * Lifts UseSignalR(r => r.MapHub<ComponentHub>()) into startup and replaces it with a shorthand for MapHub using endpoint routing. * Adds extension methods to map components to selectors for a given hub. * Updates the razor component templates to include prerendering and use a razor page as the entry point.
1 parent ea97934 commit 2d9cba8

File tree

50 files changed

+1071
-443
lines changed

Some content is hidden

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

50 files changed

+1071
-443
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using Microsoft.AspNetCore.Components.Server;
7+
8+
namespace Microsoft.AspNetCore.Builder
9+
{
10+
/// <summary>
11+
/// Extensions for <see cref="IEndpointConventionBuilder"/>.
12+
/// </summary>
13+
public static class ComponentEndpointConventionBuilderExtensions
14+
{
15+
/// <summary>
16+
/// Adds <typeparamref name="TComponent"/> to the list of components registered with this <see cref="ComponentHub"/> instance.
17+
/// </summary>
18+
/// <typeparam name="TComponent">The component type.</typeparam>
19+
/// <param name="builder">The <see cref="IEndpointConventionBuilder"/>.</param>
20+
/// <param name="selector">A CSS selector that identifies the DOM element into which the <typeparamref name="TComponent"/> will be placed.</param>
21+
/// <returns>The <paramref name="builder"/>.</returns>
22+
public static IEndpointConventionBuilder AddComponent<TComponent>(this IEndpointConventionBuilder builder, string selector)
23+
{
24+
if (builder == null)
25+
{
26+
throw new ArgumentNullException(nameof(builder));
27+
}
28+
29+
if (selector == null)
30+
{
31+
throw new ArgumentNullException(nameof(selector));
32+
}
33+
34+
return AddComponent(builder, typeof(TComponent), selector);
35+
}
36+
37+
/// <summary>
38+
/// Adds <paramref name="componentType"/> to the list of components registered with this <see cref="ComponentHub"/> instance.
39+
/// The selector will default to the component name in lowercase.
40+
/// </summary>
41+
/// <param name="builder">The <see cref="IEndpointConventionBuilder"/>.</param>
42+
/// <param name="componentType">The component type.</param>
43+
/// <param name="selector">The component selector in the DOM for the <paramref name="componentType"/>.</param>
44+
/// <returns>The <paramref name="builder"/>.</returns>
45+
public static IEndpointConventionBuilder AddComponent(this IEndpointConventionBuilder builder, Type componentType, string selector)
46+
{
47+
if (builder == null)
48+
{
49+
throw new ArgumentNullException(nameof(builder));
50+
}
51+
52+
if (componentType == null)
53+
{
54+
throw new ArgumentNullException(nameof(componentType));
55+
}
56+
57+
if (selector == null)
58+
{
59+
throw new ArgumentNullException(nameof(selector));
60+
}
61+
62+
builder.Add(endpointBuilder => AddComponent(endpointBuilder.Metadata, componentType, selector));
63+
return builder;
64+
}
65+
66+
private static void AddComponent(IList<object> metadata, Type type, string selector)
67+
{
68+
metadata.Add(new ComponentDescriptor
69+
{
70+
ComponentType = type,
71+
Selector = selector
72+
});
73+
}
74+
}
75+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using Microsoft.AspNetCore.Components.Server;
6+
using Microsoft.AspNetCore.Routing;
7+
8+
namespace Microsoft.AspNetCore.Builder
9+
{
10+
/// <summary>
11+
/// Extensions for <see cref="IEndpointRouteBuilder"/>.
12+
/// </summary>
13+
public static class ComponentEndpointRouteBuilderExtensions
14+
{
15+
/// <summary>
16+
/// Maps the SignalR <see cref="ComponentHub"/> to the path <paramref name="path"/> and associates
17+
/// the component <typeparamref name="TComponent"/> to this hub instance as the given DOM <paramref name="selector"/>.
18+
/// </summary>
19+
/// <typeparam name="TComponent">The first <see cref="IComponent"/> associated with this <see cref="ComponentHub"/>.</typeparam>
20+
/// <param name="routes">The <see cref="RouteBuilder"/>.</param>
21+
/// <param name="selector">The selector for the <typeparamref name="TComponent"/>.</param>
22+
/// <returns>The <see cref="IEndpointConventionBuilder"/>.</returns>
23+
public static IEndpointConventionBuilder MapComponentHub<TComponent>(
24+
this IEndpointRouteBuilder routes,
25+
string selector)
26+
{
27+
if (routes == null)
28+
{
29+
throw new ArgumentNullException(nameof(routes));
30+
}
31+
32+
if (selector == null)
33+
{
34+
throw new ArgumentNullException(nameof(selector));
35+
}
36+
37+
return routes.MapComponentHub(typeof(TComponent), selector, ComponentHub.DefaultPath);
38+
}
39+
40+
/// <summary>
41+
/// Maps the SignalR <see cref="ComponentHub"/> to the path <paramref name="path"/> and associates
42+
/// the component <typeparamref name="TComponent"/> to this hub instance as the given DOM <paramref name="selector"/>.
43+
/// </summary>
44+
/// <typeparam name="TComponent">The first <see cref="IComponent"/> associated with this <see cref="ComponentHub"/>.</typeparam>
45+
/// <param name="routes">The <see cref="RouteBuilder"/>.</param>
46+
/// <param name="selector">The selector for the <typeparamref name="TComponent"/>.</param>
47+
/// <param name="path">The path to map to which the <see cref="ComponentHub"/> will be mapped.</param>
48+
/// <returns>The <see cref="IEndpointConventionBuilder"/>.</returns>
49+
public static IEndpointConventionBuilder MapComponentHub<TComponent>(
50+
this IEndpointRouteBuilder routes,
51+
string selector,
52+
string path)
53+
{
54+
if (routes == null)
55+
{
56+
throw new ArgumentNullException(nameof(routes));
57+
}
58+
59+
if (path == null)
60+
{
61+
throw new ArgumentNullException(nameof(path));
62+
}
63+
64+
if (selector == null)
65+
{
66+
throw new ArgumentNullException(nameof(selector));
67+
}
68+
69+
return routes.MapComponentHub(typeof(TComponent), selector, path);
70+
}
71+
72+
/// <summary>
73+
/// Maps the SignalR <see cref="ComponentHub"/> to the path <paramref name="path"/> and associates
74+
/// the component <paramref name="componentType"/> to this hub instance as the given DOM <paramref name="selector"/>.
75+
/// </summary>
76+
/// <param name="routes">The <see cref="RouteBuilder"/>.</param>
77+
/// <param name="componentType">The first <see cref="IComponent"/> associated with this <see cref="ComponentHub"/>.</param>
78+
/// <param name="selector">The selector for the <paramref name="componentType"/>.</param>
79+
/// <param name="path">The path to map to which the <see cref="ComponentHub"/> will be mapped.</param>
80+
/// <returns>The <see cref="IEndpointConventionBuilder"/>.</returns>
81+
public static IEndpointConventionBuilder MapComponentHub(
82+
this IEndpointRouteBuilder routes,
83+
Type componentType,
84+
string selector,
85+
string path)
86+
{
87+
if (routes == null)
88+
{
89+
throw new ArgumentNullException(nameof(routes));
90+
}
91+
92+
if (path == null)
93+
{
94+
throw new ArgumentNullException(nameof(path));
95+
}
96+
97+
if (componentType == null)
98+
{
99+
throw new ArgumentNullException(nameof(componentType));
100+
}
101+
102+
if (selector == null)
103+
{
104+
throw new ArgumentNullException(nameof(selector));
105+
}
106+
107+
return routes.MapHub<ComponentHub>(path).AddComponent(componentType, selector);
108+
}
109+
}
110+
}

src/Components/Server/src/Builder/RazorComponentsApplicationBuilderExtensions.cs

Lines changed: 0 additions & 91 deletions
This file was deleted.

src/Components/Server/src/Builder/RazorComponentsOptions.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/Components/Server/src/Builder/ServerSideComponentsApplicationBuilder.cs

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/Components/Server/src/Circuits/CircuitFactory.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ namespace Microsoft.AspNetCore.Components.Server.Circuits
88
{
99
internal abstract class CircuitFactory
1010
{
11-
public abstract CircuitHost CreateCircuitHost(HttpContext httpContext, IClientProxy client);
11+
public abstract CircuitHost CreateCircuitHost(
12+
HttpContext httpContext,
13+
IClientProxy client,
14+
string uriAbsolute,
15+
string baseUriAbsolute);
1216
}
1317
}

0 commit comments

Comments
 (0)