@@ -38,13 +38,13 @@ public ComponentPrerenderer(
3838
3939 public Dispatcher Dispatcher => _htmlRenderer . Dispatcher ;
4040
41- public async ValueTask < IHtmlContent > PrerenderComponentAsync (
42- ViewContext viewContext ,
41+ public async ValueTask < IAsyncHtmlContent > PrerenderComponentAsync (
42+ ActionContext actionContext ,
4343 Type componentType ,
4444 RenderMode prerenderMode ,
4545 ParameterView parameters )
4646 {
47- ArgumentNullException . ThrowIfNull ( viewContext ) ;
47+ ArgumentNullException . ThrowIfNull ( actionContext ) ;
4848 ArgumentNullException . ThrowIfNull ( componentType ) ;
4949
5050 if ( ! typeof ( IComponent ) . IsAssignableFrom ( componentType ) )
@@ -53,19 +53,19 @@ public async ValueTask<IHtmlContent> PrerenderComponentAsync(
5353 }
5454
5555 // 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 ;
5757 lock ( _servicesInitializedLock )
5858 {
5959 _servicesInitializedTask ??= InitializeStandardComponentServicesAsync ( httpContext ) ;
6060 }
6161 await _servicesInitializedTask ;
6262
63- UpdateSaveStateRenderMode ( viewContext , prerenderMode ) ;
63+ UpdateSaveStateRenderMode ( actionContext , prerenderMode ) ;
6464
6565 return prerenderMode switch
6666 {
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 ) ,
6969 RenderMode . Static => await StaticComponentAsync ( httpContext , componentType , parameters ) ,
7070 RenderMode . WebAssembly => NonPrerenderedWebAssemblyComponent ( componentType , parameters ) ,
7171 RenderMode . WebAssemblyPrerendered => await PrerenderedWebAssemblyComponentAsync ( httpContext , componentType , parameters ) ,
@@ -101,29 +101,30 @@ private async ValueTask<HtmlComponent> PrerenderComponentCoreAsync(
101101 }
102102 }
103103
104- private static ServerComponentInvocationSequence GetOrCreateInvocationId ( ViewContext viewContext )
104+ private static ServerComponentInvocationSequence GetOrCreateInvocationId ( ActionContext actionContext )
105105 {
106- if ( ! viewContext . Items . TryGetValue ( ComponentSequenceKey , out var result ) )
106+ if ( ! actionContext . HttpContext . Items . TryGetValue ( ComponentSequenceKey , out var result ) )
107107 {
108108 result = new ServerComponentInvocationSequence ( ) ;
109- viewContext . Items [ ComponentSequenceKey ] = result ;
109+ actionContext . HttpContext . Items [ ComponentSequenceKey ] = result ;
110110 }
111111
112112 return ( ServerComponentInvocationSequence ) result ;
113113 }
114114
115115 // Internal for test only
116- internal static void UpdateSaveStateRenderMode ( ViewContext viewContext , RenderMode mode )
116+ internal static void UpdateSaveStateRenderMode ( ActionContext actionContext , RenderMode mode )
117117 {
118+ // TODO: This will all have to change when we support multiple render modes in the same response
118119 if ( mode == RenderMode . ServerPrerendered || mode == RenderMode . WebAssemblyPrerendered )
119120 {
120- if ( ! viewContext . Items . TryGetValue ( InvokedRenderModesKey , out var result ) )
121+ if ( ! actionContext . HttpContext . Items . TryGetValue ( InvokedRenderModesKey , out var result ) )
121122 {
122123 result = new InvokedRenderModes ( mode is RenderMode . ServerPrerendered ?
123124 InvokedRenderModes . Mode . Server :
124125 InvokedRenderModes . Mode . WebAssembly ) ;
125126
126- viewContext . Items [ InvokedRenderModesKey ] = result ;
127+ actionContext . HttpContext . Items [ InvokedRenderModesKey ] = result ;
127128 }
128129 else
129130 {
@@ -152,7 +153,7 @@ internal static InvokedRenderModes.Mode GetPersistStateRenderMode(ViewContext vi
152153 }
153154 }
154155
155- private async ValueTask < IHtmlContent > StaticComponentAsync ( HttpContext context , Type type , ParameterView parametersCollection )
156+ private async ValueTask < IAsyncHtmlContent > StaticComponentAsync ( HttpContext context , Type type , ParameterView parametersCollection )
156157 {
157158 var htmlComponent = await PrerenderComponentCoreAsync (
158159 parametersCollection ,
@@ -161,7 +162,7 @@ private async ValueTask<IHtmlContent> StaticComponentAsync(HttpContext context,
161162 return new PrerenderedComponentHtmlContent ( _htmlRenderer . Dispatcher , htmlComponent , null , null ) ;
162163 }
163164
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 )
165166 {
166167 if ( ! context . Response . HasStarted )
167168 {
@@ -182,7 +183,7 @@ private async Task<IHtmlContent> PrerenderedServerComponentAsync(HttpContext con
182183 return new PrerenderedComponentHtmlContent ( _htmlRenderer . Dispatcher , htmlComponent , marker , null ) ;
183184 }
184185
185- private async ValueTask < IHtmlContent > PrerenderedWebAssemblyComponentAsync ( HttpContext context , Type type , ParameterView parametersCollection )
186+ private async ValueTask < IAsyncHtmlContent > PrerenderedWebAssemblyComponentAsync ( HttpContext context , Type type , ParameterView parametersCollection )
186187 {
187188 var marker = WebAssemblyComponentSerializer . SerializeInvocation (
188189 type ,
@@ -197,7 +198,7 @@ private async ValueTask<IHtmlContent> PrerenderedWebAssemblyComponentAsync(HttpC
197198 return new PrerenderedComponentHtmlContent ( _htmlRenderer . Dispatcher , htmlComponent , null , marker ) ;
198199 }
199200
200- private IHtmlContent NonPrerenderedServerComponent ( HttpContext context , ServerComponentInvocationSequence invocationId , Type type , ParameterView parametersCollection )
201+ private IAsyncHtmlContent NonPrerenderedServerComponent ( HttpContext context , ServerComponentInvocationSequence invocationId , Type type , ParameterView parametersCollection )
201202 {
202203 if ( ! context . Response . HasStarted )
203204 {
@@ -208,7 +209,7 @@ private IHtmlContent NonPrerenderedServerComponent(HttpContext context, ServerCo
208209 return new PrerenderedComponentHtmlContent ( null , null , marker , null ) ;
209210 }
210211
211- private static IHtmlContent NonPrerenderedWebAssemblyComponent ( Type type , ParameterView parametersCollection )
212+ private static IAsyncHtmlContent NonPrerenderedWebAssemblyComponent ( Type type , ParameterView parametersCollection )
212213 {
213214 var marker = WebAssemblyComponentSerializer . SerializeInvocation ( type , parametersCollection , prerendered : false ) ;
214215 return new PrerenderedComponentHtmlContent ( null , null , null , marker ) ;
0 commit comments