Skip to content

Fix FluentKeyCode serialization in AOT apps - #5188

Merged
Denis Voituron (dvoituron) merged 2 commits into
microsoft:dev-v5from
JamesNK:fix/keycode-aot-serialization
Aug 22, 2026
Merged

Denis Voituron (dvoituron) merged 2 commits into
microsoft:dev-v5from
JamesNK:fix/keycode-aot-serialization

Conversation

@JamesNK

@JamesNK James Newton-King (JamesNK) commented Aug 22, 2026 •

Copy link
Copy Markdown
Member

Pull Request

📖 Description

FluentKeyCode passed a deferred LINQ union as a JavaScript interop argument when IgnoreModifier was enabled. The resulting internal iterator type cannot be named by System.Text.Json source generation, causing serialization to fail in AOT applications.

This change materializes the ignored-key union as a concrete KeyCode[] before invoking JavaScript. It preserves the existing filtering and duplicate-removal behavior while making the argument compatible with AOT serialization.

🎫 Issues

This issue was found while running Fluent UI Blazor with AOT on .NET 11 as part of microsoft/aspire#19565.

👩‍💻 Reviewer Notes

The behavioral change is limited to the type of the ignored-keys JavaScript interop argument. The regression test verifies that custom ignored keys and modifier keys are passed as one deduplicated KeyCode[].

No additional smoke test is required beyond the focused unit tests.

📑 Test Plan

  • dotnet test tests/Core/Components.Tests.csproj --configuration Debug --filter "FullyQualifiedName~FluentKeyCodeTests" (18 passed)
  • dotnet build src/Core/Microsoft.FluentUI.AspNetCore.Components.csproj --configuration Debug (0 warnings, 0 errors)

✅ Checklist

General

  • I have added tests for my changes.
  • I have tested my changes.
  • I have updated the project documentation to reflect my changes.
  • I have read the CONTRIBUTING documentation and followed the standards for this project.

Component-specific

  • I have added a new component
  • I have added Unit Tests for my new component
  • I have modified an existing component
  • I have validated the Unit Tests for an existing component

⏭ Next Steps

None.

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 fixes an AOT serialization failure in FluentKeyCode by ensuring the ignored-keys argument passed through JS interop is a concrete KeyCode[] rather than a deferred LINQ iterator type, which System.Text.Json source generation can’t serialize in AOT scenarios.

Changes:

  • Materialize Ignore.Union(_Modifiers) via ToArray() before invoking RegisterKeyCode in JS interop.
  • Add a unit test asserting the JS interop ignored-keys argument is a deduplicated KeyCode[] when modifier ignoring is enabled.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Core/Components/KeyCode/FluentKeyCode.razor.cs Materializes the ignored-keys union to a KeyCode[] for AOT-friendly JS interop serialization.
tests/Core/Components/KeyCode/FluentKeyCodeTests.razor Adds a regression test validating the interop argument type and deduplicated contents.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/Core/Components/KeyCode/FluentKeyCodeTests.razor Outdated
@JamesNK

Copy link
Copy Markdown
Member Author

Javier Calvarro Nelson (@javiercn) FYI, this AOT serialization issue was found while running Fluent UI Blazor with AOT on .NET 11 as part of microsoft/aspire#19565.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@dvoituron
Denis Voituron (dvoituron) merged commit 4bb1662 into microsoft:dev-v5 Aug 22, 2026
3 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.

3 participants