fix: [v5] FluentTextInput throws from ElementInternals during .NET 11 enhanced form navigation

Open Beginner friendly
#5,721 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
73/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
csharp, javascript
Domain
frontend, testing

Research direction

Start with the FluentTextInput custom element’s setCustomValidity implementation, identified in the browser stack as coming from Microsoft.FluentUI.AspNetCore.Components.lib.module.js, and trace its validation lifecycle through ValidationEngine.ts and BlazorAdapter.ts. Reproduce with the supplied .NET 11 static SSR form and enhanced-navigation steps. Done when clearing custom validity no longer throws during teardown and the control still supports client validation; the issue also requests a regression test.

Written by the indexing model from the issue text.

Description

🐛 Bug Report

💻 Repro or Code Sample

Use Fluent UI Blazor 5.1.0 with .NET 11 in a statically rendered Blazor Web App.

Render an EditForm with DataAnnotationsValidator and a FluentTextInput bound to a model property with a client validation rule:

<EditForm Model="Input" FormName="profile" OnValidSubmit="SubmitAsync" method="post">
    <DataAnnotationsValidator />

    <FluentTextInput
        Name="Input.PhoneNumber"
        @bind-Value="Input.PhoneNumber"
        Label="Phone number" />

    <FluentButton Type="ButtonType.Submit">Save</FluentButton>
</EditForm>
private sealed class InputModel
{
    [Phone]
    [Display(Name = "Phone number")]
    public string? PhoneNumber { get; set; }
}
  1. Open the page through static SSR.
  2. Navigate away using Blazor enhanced navigation.
  3. Observe the browser console while the enhanced-navigation DOM update removes the previous page.

I reproduced this on an account profile page by navigating away from /Account/Manage.

A temporary workaround is:

<DataAnnotationsValidator DisableClientValidation="true" />

DataAnnotations validation continues to run server-side, but ASP.NET Core doesn't register the Fluent custom element with its browser validation adapter.

🤔 Expected Behavior

FluentTextInput should participate in ASP.NET Core's enhanced client validation without throwing when the form page is removed from the DOM.

Calling setCustomValidity('') should clear custom validity rather than leave customError active with an empty validation message.

😯 Current Behavior

Enhanced navigation throws:

Uncaught TypeError: Failed to execute 'setValidity' on 'ElementInternals':
The second argument should not be empty if one or more flags in the first argument are true.

Stack:

at HTMLElement.setCustomValidity (Microsoft.FluentUI.AspNetCore.Components.lib.module.js)
at Qs.unregisterElement (ValidationEngine.ts:69:15)
at HTMLElement.teardown (BlazorAdapter.ts:133:16)
at HTMLElement.disconnectedCallback (BlazorAdapter.ts:98:12)
at treatAsDeletion (DomSync.ts:243:16)
at synchronizeDomContentCore (DomSync.ts:137:11)

In .NET 11, the client validation adapter locates the form control by its name attribute. For FluentTextInput, this finds the <fluent-text-input> form-associated custom-element host. During enhanced-navigation teardown, ASP.NET Core calls:

element.setCustomValidity('');

The Fluent implementation currently calls ElementInternals.setValidity with an active custom-error flag even when the supplied message is empty:

setCustomValidity(e) {
    this.elementInternals.setValidity({ customError: true }, e);
    this.reportValidity();
}

Chromium rejects the resulting setValidity({ customError: true }, '') call.

💁 Possible Solution

When clearing custom validity, pass a false/empty validity state and no non-empty message requirement. For example, only set customError when the message is nonempty and let an empty call clear the custom validity state.

Please also consider adding a .NET 11 static SSR / enhanced-navigation regression test using a form-associated FluentTextInput and DataAnnotationsValidator.

Related: microsoft/fluentui#28724. That older web-components report describes the same ElementInternals.setValidity empty-message exception and was soft-closed in 2024. The .NET 11 enhanced client-validation lifecycle provides a current, reproducible trigger for the issue.

I’m willing to help with a minimal reproduction or validate a fix.

🔦 Context

The application uses Fluent UI Blazor controls for Identity account-management forms. The exception interrupts enhanced-navigation DOM synchronization when navigating away from a form page, resulting in a browser-console error and potentially incomplete enhanced-navigation cleanup.

🌍 Your Environment

  • OS & Device: Windows 11 26H2 (build 26300), 64-bit PC
  • Browser: Microsoft Edge 158.0.4370.45
  • .NET SDK: 11.0.100
  • ASP.NET Core / Blazor: 11.0.0
  • Microsoft.FluentUI.AspNetCore.Components: 5.1.0
  • Rendering model: Blazor Web App, static SSR with enhanced navigation
Dominant language
C#
Stars
4.9k
Forks
500
Avg merge
15h 28m
Merged PRs (30d)
58

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/fluentui-blazor

All issues in microsoft/fluentui-blazor

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.