Skip to content

Fix FluentKeyCodeProvider error on using browser autocomplete with InputText#5030

Open
najlot wants to merge 1 commit into
microsoft:dev-v5from
najlot:dev-v5
Open

Fix FluentKeyCodeProvider error on using browser autocomplete with InputText#5030
najlot wants to merge 1 commit into
microsoft:dev-v5from
najlot:dev-v5

Conversation

@najlot

@najlot najlot commented Jul 20, 2026

Copy link
Copy Markdown

Pull Request

📖 Description

Hello everyone!
I've been trying to get FluentUI Blazor into an existing Blazor WebAssembly application.
After I've added FluentUI.Blazor like it is described in
https://v5.fluentui-blazor.net/installation
i've got an error as I tried to log in.

So there is a fix for that.

Stack trace I've got:

Message=
Source=
StackTrace:
at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_ExpectedNumber(JsonTokenType tokenType)
at System.Text.Json.Utf8JsonReader.TryGetInt32(Int32& value)
at System.Text.Json.Utf8JsonReader.GetInt32()
at System.Text.Json.Serialization.Converters.Int32Converter.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
at System.Text.Json.Serialization.JsonConverter1[[System.Int32, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, Int32& value, Boolean& isPopulatedValue) at System.Text.Json.Serialization.JsonConverter1[[System.Int32, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ReadCore(Utf8JsonReader& reader, Int32& value, JsonSerializerOptions options, ReadStack& state)
Exception_EndOfInnerExceptionStack
at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, Utf8JsonReader& reader, Exception ex)
at System.Text.Json.Serialization.JsonConverter1[[System.Int32, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ReadCore(Utf8JsonReader& reader, Int32& value, JsonSerializerOptions options, ReadStack& state) at System.Text.Json.Serialization.Metadata.JsonTypeInfo1[[System.Int32, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Deserialize(Utf8JsonReader& reader, ReadStack& state)
at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1[[System.Int32, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].DeserializeAsObject(Utf8JsonReader& reader, ReadStack& state)
at System.Text.Json.JsonSerializer.ReadAsObject(Utf8JsonReader& reader, JsonTypeInfo jsonTypeInfo)
at System.Text.Json.JsonSerializer.Deserialize(Utf8JsonReader& reader, Type returnType, JsonSerializerOptions options)
at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.ParseArguments(JSRuntime jsRuntime, String methodIdentifier, String arguments, Type[] parameterTypes)
at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.InvokeSynchronously(JSRuntime jsRuntime, DotNetInvocationInfo& callInfo, IDotNetObjectReference objectReference, String argsJson)
at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.BeginInvokeDotNet(JSRuntime jsRuntime, DotNetInvocationInfo invocationInfo, String argsJson)
at w.endInvokeDotNetFromJS (http://localhost:5270/_framework/blazor.webassembly.w3qd1tpl0e.js:1:4504)
at Object.tn [as endInvokeDotNetFromJS] (http://localhost:5270/_framework/blazor.webassembly.w3qd1tpl0e.js:1:59313)
at http://localhost:5270/_framework/dotnet.runtime.web2r9gqbh.js:3:34587
at Mc (http://localhost:5270/_framework/dotnet.runtime.web2r9gqbh.js:3:175837)
at http://localhost:5270/_framework/dotnet.native.u31nt9bth6.wasm:wasm-function[298]:0x1f797
at http://localhost:5270/_framework/dotnet.native.u31nt9bth6.wasm:wasm-function[222]:0x1ca98
at http://localhost:5270/_framework/dotnet.native.u31nt9bth6.wasm:wasm-function[213]:0xebe7
at http://localhost:5270/_framework/dotnet.native.u31nt9bth6.wasm:wasm-function[256]:0x1d974
at http://localhost:5270/_framework/dotnet.native.u31nt9bth6.wasm:wasm-function[3231]:0xf1888
at http://localhost:5270/_framework/dotnet.native.u31nt9bth6.wasm:wasm-function[2553]:0xc7139

🎫 Issues

No issue created as there is the fix.

👩‍💻 Reviewer Notes

There is what I've done:
FluentUI-Blazor-KeyCode

📑 Test Plan

I've got an simple example app where the issue can be reproduced:
example_app.zip

✅ Checklist

General

  • I have added tests for my changes.
  • I have tested my changes. -> I've had some issues to get the project running in my project
  • I have updated the project documentation to reflect my changes. -> I could not find documentation that need changes.
  • I have read the CONTRIBUTING documentation and followed the standards for this project.

Component-specific

  • I have modified an existing component
  • I have validated the Unit Tests for an existing component

⏭ Next Steps

@najlot
najlot requested review from dvoituron and vnbaaij as code owners July 20, 2026 21:39
Copilot AI review requested due to automatic review settings July 20, 2026 21:39
@najlot

najlot commented Jul 20, 2026

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens the FluentKeyCode JavaScript interop against malformed/partial keyboard events (e.g., events missing numeric/boolean properties), preventing System.Text.Json deserialization failures when Blazor receives the event payload.

Changes:

  • Normalize keyboard event fields (keyCode, modifier flags, location, repeat, key) before invoking .NET (invokeMethodAsync) to ensure stable argument types.
  • Add a Playwright integration test + minimal Razor page that reproduces a “keydown event missing properties” scenario and asserts the component reports default values instead of throwing.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
tests/Integration/Components/KeyCode/FluentKeyCodeTests.cs Adds an integration test that dispatches a malformed keydown event and verifies default output values.
tests/Integration/Components/KeyCode/Examples/MalformedKeyboardEventPage.razor Adds a dedicated test page wiring FluentKeyCode to an input and rendering observed event values for assertions.
src/Core/Components/KeyCode/FluentKeyCode.razor.ts Normalizes event argument types before JS→.NET invocation to avoid JSON token type errors.

@dvoituron dvoituron left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Need more time to validate 😊

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.

3 participants