Skip to content

[Blazor] InputBase - SetCurrentValueAsync + SetCurrentValueAsStringAsync (fix for #44105) #54279

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

Closed

Conversation

hakenr
Copy link
Member

@hakenr hakenr commented Mar 1, 2024

Proper Asynchronous Handling for ValueChanged Callback

Fixes #44105

Description

  • Failing E2E tests were introduced in the first commit (the tests demonstrate just one of the issues related to the original implementation).
  • The fix was introduced in the second commit (tests passed).
  • Backwards compatibility is preserved.
  • New public APIs have been introduced:
    Microsoft.AspNetCore.Components.Forms.InputBase<TValue>.SetCurrentValueAsStringAsync(string? value) -> System.Threading.Tasks.Task!
    Microsoft.AspNetCore.Components.Forms.InputBase<TValue>.SetCurrentValueAsync(TValue? value) -> System.Threading.Tasks.Task!
    

I'm willing to continue collaborating on this PR if I receive a code review and further refinements are needed.

cc @jirikanda

@hakenr hakenr requested a review from a team as a code owner March 1, 2024 00:26
@ghost ghost added the area-blazor Includes: Blazor, Razor Components label Mar 1, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Mar 1, 2024
Copy link
Contributor

Thanks for your PR, @hakenr. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

…g) hides inherited member InputBase<T>.SetCurrentValueAsStringAsync(string?)
@hakenr
Copy link
Member Author

hakenr commented Mar 1, 2024

The third commit fixes InputBaseTest (and related) where the SetCurrentValueAsStringAsync() method was already used.
It seems these tests can be refactored to use the new asynchronous InputBase methods.
Let me know if I should do so.

@hakenr
Copy link
Member Author

hakenr commented Mar 1, 2024

Now it seems the failing tests are unrelated (HTTP/2, HTTP/3).

@hakenr
Copy link
Member Author

hakenr commented Mar 1, 2024

/azp run

Copy link

Commenter does not have sufficient privileges for PR 54279 in repo dotnet/aspnetcore

Copy link
Contributor

Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime.
To make sure no conflicting changes have occurred, please rerun validation before merging. You can do this by leaving an /azp run comment here (requires commit rights), or by simply closing and reopening.

@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Mar 11, 2024
@MackinnonBuck
Copy link
Member

Thanks for the contribution, @hakenr. We're interested in taking this change, but it has to go through API review first. Would you be willing to fill out a new issue using the API Proposal template? Its content would probably be quite similar to what you already wrote in #44105. This will allow us to prioritize reviewing the changes here.

@hakenr
Copy link
Member Author

hakenr commented Dec 12, 2024

Thanks for the contribution, @hakenr. We're interested in taking this change, but it has to go through API review first. Would you be willing to fill out a new issue using the API Proposal template? Its content would probably be quite similar to what you already wrote in #44105. This will allow us to prioritize reviewing the changes here.

I will try to submit the API Proposal as requested.

@javiercn
Copy link
Member

javiercn commented Mar 7, 2025

@hanenR sorry it took us a while to get back to this PR.

We had an "intense" discussion within the team a couple months back and we had to summarize the discussion.

We discuss the possibility of awaiting ValueChanged.InvokeAsync and we've come to the conclusion that we prefer the most scoped solution of not awaiting it and instead reporting the error through the renderer API.

The reason for this is that it is very easy to get into a situation where if your binding does async work, any high throughput input will result in the state between the control and the input getting out of sync.

For example, having an input that does some async work and then capitalizes the value would cause a sequence of events like
a -> async work(a)
ab -> async work(ab)
async work(ab) completes -> AB
async work(a) completes -> A

Right now there's no support for cancellation on InvokeAsync so we think it's best to recommend that bindings don't do async work as part of the binding and that any long running work is handled separately in a queue with cancellation.

We would still take this PR if we scope down the change to avoid the await ValueChanged.InvokeAsync(Value); and use _renderHandle.DispatchExceptionAsync to flow the exception correctly.

@javiercn javiercn added the pr: pending author input For automation. Specifically separate from Needs: Author Feedback label Mar 7, 2025
Copy link
Contributor

Hi @hakenr.
It seems you haven't touched this PR for the last two weeks. To avoid accumulating old PRs, we're marking it as stale. As a result, it will be closed if no further activity occurs within 4 days of this comment. You can learn more about our Issue Management Policies here.

@dotnet-policy-service dotnet-policy-service bot added the stale Indicates a stale issue. These issues will be closed automatically soon. label Mar 17, 2025
@hakenr
Copy link
Member Author

hakenr commented Mar 17, 2025

@javiercn, as I already said in #59477 (the API Proposal requested)

Thanks for taking the time to discuss this. I understand your concerns about changing the behavior of existing components and the extra work required to cover all scenarios.

Unfortunately, the proposed solution of handling and dispatching the exception still follows the fire-and-forget approach, without giving derived components the opportunity to handle it more effectively.

Did you consider an option where the default processing remains synchronous (fire-and-forget, as it is now) while introducing an asynchronous alternative (such as SetCurrentValueAsStringAsync()) to allow derived components to take responsibility and handle it asynchronously?

(Unfortunately, I don't align with the currently proposed solution of "handling and dispatching the exception only," as it doesn't fix the problem but merely patches one of its symptoms. I’m not willing to invest my effort in such a pull request or put my name behind it, sorry.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components community-contribution Indicates that the PR has been added by a community member pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun pr: pending author input For automation. Specifically separate from Needs: Author Feedback stale Indicates a stale issue. These issues will be closed automatically soon.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Blazor] Input* - allow correct async handling of ValueChanged callbacks (incl. @bind-Value:after)
4 participants