Fix nullable annotation for ElementReference.Id#66645
Open
sheiksyedm wants to merge 6 commits into
Open
Conversation
ElementReference is a struct that can be initialized via parameterless constructor or default(), leaving Id as null. Mark Id as string? to correctly reflect this possibility. Fixes dotnet#58523
Contributor
|
Thanks for your PR, @sheiksyedm. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
Contributor
There was a problem hiding this comment.
Pull request overview
Corrects the nullable annotation of Microsoft.AspNetCore.Components.ElementReference.Id to reflect that ElementReference is a struct and may be default-initialized with Id == null, reducing false nullable-analyzer warnings for consumers.
Changes:
- Updated
ElementReference.Idfromstringtostring?. - Updated
PublicAPI.Shipped.txtto reflect the corrected nullability metadata.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Components/Components/src/ElementReference.cs | Updates Id nullability to match default(struct) behavior. |
| src/Components/Components/src/PublicAPI.Shipped.txt | Updates shipped API metadata for the Id getter nullability. |
This reverts commit 1aa67cb.
PublicAPI.Shipped.txt must not be modified directly. Use *REMOVED* + new entry pattern in Unshipped.txt per docs/APIBaselines.md.
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ElementReference is a struct, so it can be initialized via the parameterless constructor (new ElementReference()) or default(ElementReference), both of which leave Id as null. The current non-nullable annotation (string) is incorrect and causes false analyzer warnings when users write null-safe code.
Changes
Impact
This is a metadata-only change (nullable annotation). No runtime behavior is affected. Users who already handle null correctly will no longer see suppression warnings, and those who don't will now get proper compiler guidance.
Fixes #58523