-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add test coverage for prerendering closed generic components #64643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Greetings! You've submitted a PR that modifies code that is shared with https://github.com/dotnet/runtime . Please make sure you synchronize this code with the changes in that repo! |
Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
There was a problem hiding this comment.
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 adds comprehensive test coverage verifying that closed generic components can be successfully prerendered in Blazor applications. The investigation revealed that this functionality already works correctly—no code changes were needed, only test coverage was missing.
Key changes:
- Created a reusable
GenericComponent<TValue>test component for validating generic type handling - Added 4 tests to
ServerComponentDeserializerTestcovering serialization/deserialization of closed generic components - Added 4 tests to
EndpointHtmlRendererTestcovering various rendering modes (static, Interactive Server, Interactive WebAssembly)
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Components/Endpoints/test/TestComponents/GenericComponent.razor | New test component demonstrating a generic component with a type parameter that can be prerendered |
| src/Components/Server/test/Circuits/ServerComponentDeserializerTest.cs | Added 4 tests verifying that closed generic components can be serialized and deserialized correctly, with and without parameters |
| src/Components/Endpoints/test/EndpointHtmlRendererTest.cs | Added 4 tests covering static rendering and prerendering of closed generic components in different render modes (Server and WebAssembly) |
| var parameters = deserializedDescriptor.Parameters.ToDictionary(); | ||
| Assert.Single(parameters); | ||
| Assert.Contains("Value", parameters.Keys); | ||
| Assert.Equal(42, Convert.ToInt32(parameters["Value"]!, CultureInfo.InvariantCulture)); |
Copilot
AI
Dec 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of Convert.ToInt32 with CultureInfo.InvariantCulture is unnecessary here. The parameter value is already an integer (42), and after deserialization it should be directly castable or assertable. In similar tests in this file (e.g., CanParseSingleMarkerWithParameters at line 56), values are asserted directly without conversion.
Consider simplifying to:
Assert.Equal(42, parameters["Value"]);If type conversion is genuinely needed due to JSON deserialization, consider using a direct cast instead:
Assert.Equal(42, Assert.IsType<JsonElement>(parameters["Value"]).GetInt32());| Assert.Equal(42, Convert.ToInt32(parameters["Value"]!, CultureInfo.InvariantCulture)); | |
| Assert.Equal(42, parameters["Value"]); |
Add test coverage for prerendering closed generic components
Add tests verifying closed generic components can be prerendered
Description
The issue reported that generic components couldn't be rendered as root components due to type serialization limitations. Investigation shows the feature already works correctly:
Type.FullNameproduces valid assembly-qualified names for closed generics (e.g.,GenericComponent1[[System.Int32, System.Private.CoreLib, ...]]`)Assembly.GetType()correctly resolves these names during deserializationThis PR adds comprehensive test coverage:
EndpointHtmlRendererTest (4 tests)
GenericComponent<int>ServerComponentDeserializerTest (4 tests)
int,string)Usage in tests:
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.