Repository navigation
fix(select): validate on the renderer after a selection change - #215
Merged
Merged
Conversation
The SelectedValues setter started the validation with Task.Delay(30).ContinueWith(...), so BeginValidateAsync ran on a thread pool thread and changed the EditContext's field states while a render read them (NullReferenceException in EditContext.GetValidationMessages under Blazor Server and bUnit). The delayed validation now runs through InvokeAsync. MudExCodeView's delayed markup update gets the same change.
Deploying mudblazor-extensions with
|
| Latest commit: |
a88c830
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://9eb49295.mudblazor-extensions.pages.dev |
| Branch Preview URL: | https://fix-select-validate-on-rende.mudblazor-extensions.pages.dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
SelectedValuessetter ofMudExSelectstarted its delayed validation withTask.Delay(30).ContinueWith(_ => BeginValidateAsync()). The continuation ran on a thread pool thread, soBeginValidateAsync→EditContext.NotifyFieldChangedchanged the EditContext's field-state dictionary while a render read it on the renderer (e.g.HasErrorsofMudExObjectEditForm→EditContext.GetValidationMessagesthrew aNullReferenceException). Seen under Blazor Server and bUnit. Downstream proof: a FluentValidation validator recorded the stackMudExSelect.set_SelectedValues → ContinueWith → BeginValidateAsync → EditContext.NotifyFieldChangedon a pool thread in 20 of 20 runs.Fix
MudExSelect: the delayed validation now runs throughInvokeAsync(async () => { await Task.Delay(30); await BeginValidateAsync(); }), so it runs on the renderer's dispatcher.MudExCodeView: same pattern for the delayed markup update in theCodesetter (it wrote component state from a pool thread).Test
SelectValidationThreadTestsrendersMudExSelect<string>with a cascadingEditContextandFor, changesSelectedValuesand waits onEditContext.OnFieldChangedthrough aTaskCompletionSource(no sleeps). It asserts thatDispatcher.CheckAccess()was true when the field change came in. It fails with the old line and passes with the fix.