Allow streaming the loading phase of POST responses
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
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.:
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:
```html
```
We could have a component that encapsulates this, e.g., ``.
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.
Contributor guide
Assessment
This issue has not been assessed yet.