dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.59k stars 10.06k forks source link

Allow streaming the loading phase of POST responses #50994

Open SteveSandersonMS opened 1 year ago

SteveSandersonMS commented 1 year ago

While implementing forms support, we took a decision not to stream the rendering for the pre-quiescence phase of POST responses. We only stream the post-quiescence phase for POST responses, i.e., the part where we invoke the @onsubmit handler.

The justification at the time is for "edit" scenarios, e.g.:

  1. User arrives at an edit page, which first has to do some async loading before it can show the edit UI
  2. They fill in the form and submit it
  3. The server re-renders the same form, but possibly with some extra info such as validation errors

In this case, you likely want streaming on the first data load (step 1), but you don't want to re-stream the re-loading that happens on step 3 because then the whole form would momentarily disappear then reappear after loading. That is, you'd get a "flash of loading" on form submission. This would be distracting and possibly lose other state such as which form field was focused, your scroll position, etc.

However, this design choice does not account for the fact that POST is also used for purely readonly operations in some cases, such as modifying search parameters, then submitting to display updated results. In these cases you likely do want streaming the OnInitializedAsync phase when processing those POST requests.

Possible design

This should be kept decoupled from enhanced submit, since whether or not you want streaming is independent of whether you want enhanced submit. So we would need the developer to indicate their intent in some way that naturally gets submitted with a basic HTML form post (and not as a data- attribute on the form, for example). It could be done as a hidden field:

<form @formname="myform" method="post">
    <AntiforgeryToken />
    <input type="hidden" name="blazor-stream-loading" value="true" />
</form>

We could have a component that encapsulates this, e.g., <FormStreaming StreamInitialLoad="true" />.

Obviously those API names are bad and should be improved.

@mkArtakMSFT To clarify, I'm proposing this for .NET 9, not 8.

Clarification that we DO stream POST responses once @onsubmit begins

It's not correct to say we don't stream POST responses. We just don't stream the initial phase until quiescence. Once quiescence is reached, we then invoke the @onsubmit handler, and we do stream the async operations from then onwards. So it is possible to display an "Operation in progress..." UI on a typical POST form if you want.

ghost commented 1 year ago

Thanks for contacting us.

We're moving this issue to the .NET 9 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s). If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

jonhilt commented 1 year ago

+1 for this.

I'm implementing search using a form and it threw me for a moment when streaming rendering suddenly stopped working.

Bartmax commented 1 year ago

POST is also used for purely readonly operations

Forms have a method parameters that allows GET as a value and that should be used for read only operations imho.

I would suggest to enable ssr by default on forms with method="get" and leave post alone

bonus point: it has much better UX and enables link sharing opportunities which sadly lacks many searches UIs.

ghost commented 11 months ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.