@@ -38,13 +38,13 @@ public ComponentPrerenderer(
38
38
39
39
public Dispatcher Dispatcher => _htmlRenderer . Dispatcher ;
40
40
41
- public async ValueTask < IHtmlContent > PrerenderComponentAsync (
42
- ViewContext viewContext ,
41
+ public async ValueTask < IAsyncHtmlContent > PrerenderComponentAsync (
42
+ ActionContext actionContext ,
43
43
Type componentType ,
44
44
RenderMode prerenderMode ,
45
45
ParameterView parameters )
46
46
{
47
- ArgumentNullException . ThrowIfNull ( viewContext ) ;
47
+ ArgumentNullException . ThrowIfNull ( actionContext ) ;
48
48
ArgumentNullException . ThrowIfNull ( componentType ) ;
49
49
50
50
if ( ! typeof ( IComponent ) . IsAssignableFrom ( componentType ) )
@@ -53,19 +53,19 @@ public async ValueTask<IHtmlContent> PrerenderComponentAsync(
53
53
}
54
54
55
55
// Make sure we only initialize the services once, but on every call we wait for that process to complete
56
- var httpContext = viewContext . HttpContext ;
56
+ var httpContext = actionContext . HttpContext ;
57
57
lock ( _servicesInitializedLock )
58
58
{
59
59
_servicesInitializedTask ??= InitializeStandardComponentServicesAsync ( httpContext ) ;
60
60
}
61
61
await _servicesInitializedTask ;
62
62
63
- UpdateSaveStateRenderMode ( viewContext , prerenderMode ) ;
63
+ UpdateSaveStateRenderMode ( actionContext , prerenderMode ) ;
64
64
65
65
return prerenderMode switch
66
66
{
67
- RenderMode . Server => NonPrerenderedServerComponent ( httpContext , GetOrCreateInvocationId ( viewContext ) , componentType , parameters ) ,
68
- RenderMode . ServerPrerendered => await PrerenderedServerComponentAsync ( httpContext , GetOrCreateInvocationId ( viewContext ) , componentType , parameters ) ,
67
+ RenderMode . Server => NonPrerenderedServerComponent ( httpContext , GetOrCreateInvocationId ( actionContext ) , componentType , parameters ) ,
68
+ RenderMode . ServerPrerendered => await PrerenderedServerComponentAsync ( httpContext , GetOrCreateInvocationId ( actionContext ) , componentType , parameters ) ,
69
69
RenderMode . Static => await StaticComponentAsync ( httpContext , componentType , parameters ) ,
70
70
RenderMode . WebAssembly => NonPrerenderedWebAssemblyComponent ( componentType , parameters ) ,
71
71
RenderMode . WebAssemblyPrerendered => await PrerenderedWebAssemblyComponentAsync ( httpContext , componentType , parameters ) ,
@@ -101,29 +101,30 @@ private async ValueTask<HtmlComponent> PrerenderComponentCoreAsync(
101
101
}
102
102
}
103
103
104
- private static ServerComponentInvocationSequence GetOrCreateInvocationId ( ViewContext viewContext )
104
+ private static ServerComponentInvocationSequence GetOrCreateInvocationId ( ActionContext actionContext )
105
105
{
106
- if ( ! viewContext . Items . TryGetValue ( ComponentSequenceKey , out var result ) )
106
+ if ( ! actionContext . HttpContext . Items . TryGetValue ( ComponentSequenceKey , out var result ) )
107
107
{
108
108
result = new ServerComponentInvocationSequence ( ) ;
109
- viewContext . Items [ ComponentSequenceKey ] = result ;
109
+ actionContext . HttpContext . Items [ ComponentSequenceKey ] = result ;
110
110
}
111
111
112
112
return ( ServerComponentInvocationSequence ) result ;
113
113
}
114
114
115
115
// Internal for test only
116
- internal static void UpdateSaveStateRenderMode ( ViewContext viewContext , RenderMode mode )
116
+ internal static void UpdateSaveStateRenderMode ( ActionContext actionContext , RenderMode mode )
117
117
{
118
+ // TODO: This will all have to change when we support multiple render modes in the same response
118
119
if ( mode == RenderMode . ServerPrerendered || mode == RenderMode . WebAssemblyPrerendered )
119
120
{
120
- if ( ! viewContext . Items . TryGetValue ( InvokedRenderModesKey , out var result ) )
121
+ if ( ! actionContext . HttpContext . Items . TryGetValue ( InvokedRenderModesKey , out var result ) )
121
122
{
122
123
result = new InvokedRenderModes ( mode is RenderMode . ServerPrerendered ?
123
124
InvokedRenderModes . Mode . Server :
124
125
InvokedRenderModes . Mode . WebAssembly ) ;
125
126
126
- viewContext . Items [ InvokedRenderModesKey ] = result ;
127
+ actionContext . HttpContext . Items [ InvokedRenderModesKey ] = result ;
127
128
}
128
129
else
129
130
{
@@ -152,7 +153,7 @@ internal static InvokedRenderModes.Mode GetPersistStateRenderMode(ViewContext vi
152
153
}
153
154
}
154
155
155
- private async ValueTask < IHtmlContent > StaticComponentAsync ( HttpContext context , Type type , ParameterView parametersCollection )
156
+ private async ValueTask < IAsyncHtmlContent > StaticComponentAsync ( HttpContext context , Type type , ParameterView parametersCollection )
156
157
{
157
158
var htmlComponent = await PrerenderComponentCoreAsync (
158
159
parametersCollection ,
@@ -161,7 +162,7 @@ private async ValueTask<IHtmlContent> StaticComponentAsync(HttpContext context,
161
162
return new PrerenderedComponentHtmlContent ( _htmlRenderer . Dispatcher , htmlComponent , null , null ) ;
162
163
}
163
164
164
- private async Task < IHtmlContent > PrerenderedServerComponentAsync ( HttpContext context , ServerComponentInvocationSequence invocationId , Type type , ParameterView parametersCollection )
165
+ private async Task < IAsyncHtmlContent > PrerenderedServerComponentAsync ( HttpContext context , ServerComponentInvocationSequence invocationId , Type type , ParameterView parametersCollection )
165
166
{
166
167
if ( ! context . Response . HasStarted )
167
168
{
@@ -182,7 +183,7 @@ private async Task<IHtmlContent> PrerenderedServerComponentAsync(HttpContext con
182
183
return new PrerenderedComponentHtmlContent ( _htmlRenderer . Dispatcher , htmlComponent , marker , null ) ;
183
184
}
184
185
185
- private async ValueTask < IHtmlContent > PrerenderedWebAssemblyComponentAsync ( HttpContext context , Type type , ParameterView parametersCollection )
186
+ private async ValueTask < IAsyncHtmlContent > PrerenderedWebAssemblyComponentAsync ( HttpContext context , Type type , ParameterView parametersCollection )
186
187
{
187
188
var marker = WebAssemblyComponentSerializer . SerializeInvocation (
188
189
type ,
@@ -197,7 +198,7 @@ private async ValueTask<IHtmlContent> PrerenderedWebAssemblyComponentAsync(HttpC
197
198
return new PrerenderedComponentHtmlContent ( _htmlRenderer . Dispatcher , htmlComponent , null , marker ) ;
198
199
}
199
200
200
- private IHtmlContent NonPrerenderedServerComponent ( HttpContext context , ServerComponentInvocationSequence invocationId , Type type , ParameterView parametersCollection )
201
+ private IAsyncHtmlContent NonPrerenderedServerComponent ( HttpContext context , ServerComponentInvocationSequence invocationId , Type type , ParameterView parametersCollection )
201
202
{
202
203
if ( ! context . Response . HasStarted )
203
204
{
@@ -208,7 +209,7 @@ private IHtmlContent NonPrerenderedServerComponent(HttpContext context, ServerCo
208
209
return new PrerenderedComponentHtmlContent ( null , null , marker , null ) ;
209
210
}
210
211
211
- private static IHtmlContent NonPrerenderedWebAssemblyComponent ( Type type , ParameterView parametersCollection )
212
+ private static IAsyncHtmlContent NonPrerenderedWebAssemblyComponent ( Type type , ParameterView parametersCollection )
212
213
{
213
214
var marker = WebAssemblyComponentSerializer . SerializeInvocation ( type , parametersCollection , prerendered : false ) ;
214
215
return new PrerenderedComponentHtmlContent ( null , null , null , marker ) ;
0 commit comments