Skip to content

fix(select): validate on the renderer after a selection change - #215

Merged
fgilde merged 1 commit into
mainfrom
fix/select-validate-on-renderer
Dec 3, 2026
Merged

fgilde merged 1 commit into
mainfrom
fix/select-validate-on-renderer

Conversation

@fgilde

@fgilde fgilde commented Dec 3, 2026

Copy link
Copy Markdown
Owner

Problem

The SelectedValues setter of MudExSelect started its delayed validation with Task.Delay(30).ContinueWith(_ => BeginValidateAsync()). The continuation ran on a thread pool thread, so BeginValidateAsync → EditContext.NotifyFieldChanged changed the EditContext's field-state dictionary while a render read it on the renderer (e.g. HasErrors of MudExObjectEditForm → EditContext.GetValidationMessages threw a NullReferenceException). Seen under Blazor Server and bUnit. Downstream proof: a FluentValidation validator recorded the stack MudExSelect.set_SelectedValues → ContinueWith → BeginValidateAsync → EditContext.NotifyFieldChanged on a pool thread in 20 of 20 runs.

Fix

  • MudExSelect: the delayed validation now runs through InvokeAsync(async () => { await Task.Delay(30); await BeginValidateAsync(); }), so it runs on the renderer's dispatcher.
  • MudExCodeView: same pattern for the delayed markup update in the Code setter (it wrote component state from a pool thread).

Test

SelectValidationThreadTests renders MudExSelect<string> with a cascading EditContext and For, changes SelectedValues and waits on EditContext.OnFieldChanged through a TaskCompletionSource (no sleeps). It asserts that Dispatcher.CheckAccess() was true when the field change came in. It fails with the old line and passes with the fix.

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.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Deploying mudblazor-extensions with  Cloudflare Pages  Cloudflare Pages

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

View logs

@fgilde
fgilde merged commit 6498827 into main Dec 3, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant