Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streaming rendering with Azure hosting 8.0 #30820

Closed
guardrex opened this issue Oct 24, 2023 · 1 comment
Closed

Streaming rendering with Azure hosting 8.0 #30820

guardrex opened this issue Oct 24, 2023 · 1 comment
Assignees

Comments

@guardrex
Copy link
Collaborator

Description

From @iphdav on #30504 ...

I wanted to add a few comments for you to consider when writing up the documents.

I was putting together a blazor streaming rendering demo and decided to have it obtain data to display on the page from a separate minimal API that streamed back data using IAsyncEnumerable.

It worked perfectly locally, but when deployed to an Azure Web App, even my minimal API appeared to not be streaming. I was not sure the exact backend architecture of Azure (YARP respone caching, etc), but noticed if I added this after each items was yield returned (within the IAsyncEnumerable):

await context.Response.Body.FlushAsync();

It did correctly stream when deployed to Azure. Flushing the response buffer was not needed when running locally on Kestrel.

It would be interesting if this customer did the same thing in his streaming blazor project to see if it streamed correctly for his particular hosting provider when flushing the buffer after each async update to his page (when streaming rendering the response).

But if you are writing up the documents, maybe just include some general comments and suggestions including configuring the web server, but also flushing the response as shown above.

I think in RC2, the HttpContext will be registered globally as a CascadingParameter. At that point, I would be interesting to document this as a potential solution to caching (compared to the default template).

First the component would need to inject the HttpContext using the new technique (which will not work until RC2):

[CascadingParameter] HttpContext Ctx;

In the demo project template, where there is a delay awaited, to add flushing the buffer like this:

await Task.Delay(2000);
await Ctx?.Response.Body.FlushAsync();

It would be interesting to check if this worked, and include this in the docs for Azure (etc) if it does work.

Page URL

https://learn.microsoft.com/en-us/aspnet/core/blazor/components/rendering?view=aspnetcore-8.0

Content source URL

https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/blazor/components/rendering.md

Document ID

27742f9a-95e5-a2d0-aa54-0ef24cad3d2a

Article author

guardrex

@guardrex
Copy link
Collaborator Author

I finally reached this one 🏃🏃🏃🏃🏃🏃😅.

the HttpContext will be registered globally as a CascadingParameter. At that point, I would be interesting to document this as a potential solution to caching (compared to the default template).

I don't think that's a supported approach because HttpContext is only for a static server or root component. Streaming rendering in Blazor is probably often going to happen via a component class that isn't a root component.

minimal API ... added this after each items was yield returned (within the IAsyncEnumerable) ... await context.Response.Body.FlushAsync();

Possibly so, but I I'd like to see the PU address the scenario first in an issue opened on their repo.

@iphdav ... open an issue for them at ...

https://github.com/dotnet/aspnetcore/issues

You can cut-'n-paste your remarks here (the first part that pertains to hosting a Minimal API on Azure) into an issue for them to assess.

Please add ...

cc: @guardrex https://github.com/dotnet/AspNetCore.Docs/issues/30820

... to the bottom of your opening comment so that I can follow along. I might re-open this for doc work depending on what they say.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

2 participants