-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
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.:
- User arrives at an edit page, which first has to do some async loading before it can show the edit UI
- They fill in the form and submit it
- 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.