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

Do not throwing on InputBase.Dispose() if not in EditContext. #31510

Merged
merged 2 commits into from
Apr 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Components/Web/src/Forms/InputBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ protected string CssClass


/// <inheritdoc />
[MemberNotNull(nameof(EditContext), nameof(CascadedEditContext))]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine to have this since you added it, but in the ordinary case, it's not very useful. The compiler cannot deduce the component lifecycle so so it's hard for it know these properties are not-null when executing any other method on a component.

public override Task SetParametersAsync(ParameterView parameters)
{
parameters.SetParameterProperties(this);
Expand Down Expand Up @@ -315,7 +316,12 @@ protected virtual void Dispose(bool disposing)

void IDisposable.Dispose()
{
EditContext.OnValidationStateChanged -= _validationStateChangedHandler;
// When initialization in the SetParametersAsync method fails, the EditContext property can remain equal to null
if (EditContext is not null)
{
EditContext.OnValidationStateChanged -= _validationStateChangedHandler;
}

Dispose(disposing: true);
}
}
Expand Down