-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Blazor] Fix metadata comments incorrectly being processed as logical elements #64529
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,19 @@ | ||||||||||||||||||||
| // Licensed to the .NET Foundation under one or more agreements. | ||||||||||||||||||||
| // The .NET Foundation licenses this file to you under the MIT license. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // Metadata comments are consumed during discovery and should not be part of the logical tree. | ||||||||||||||||||||
| // They include: WebAssembly options, component state, and web initializers. | ||||||||||||||||||||
| export function isMetadataComment(node: Node): boolean { | ||||||||||||||||||||
| if (node.nodeType !== Node.COMMENT_NODE) { | ||||||||||||||||||||
| return false; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| const content = node.textContent || ''; | ||||||||||||||||||||
| return content.trim().startsWith('Blazor-Server-Component-State:') || | ||||||||||||||||||||
| content.trim().startsWith('Blazor-WebAssembly-Component-State:') || | ||||||||||||||||||||
| content.trim().startsWith('Blazor-Web-Initializers:') || | ||||||||||||||||||||
| content.trim().startsWith('Blazor-WebAssembly:'); | ||||||||||||||||||||
|
Comment on lines
+11
to
+14
|
||||||||||||||||||||
| return content.trim().startsWith('Blazor-Server-Component-State:') || | |
| content.trim().startsWith('Blazor-WebAssembly-Component-State:') || | |
| content.trim().startsWith('Blazor-Web-Initializers:') || | |
| content.trim().startsWith('Blazor-WebAssembly:'); | |
| const trimmedContent = content.trim(); | |
| return trimmedContent.startsWith('Blazor-Server-Component-State:') || | |
| trimmedContent.startsWith('Blazor-WebAssembly-Component-State:') || | |
| trimmedContent.startsWith('Blazor-Web-Initializers:') || | |
| trimmedContent.startsWith('Blazor-WebAssembly:'); |
Copilot
AI
Nov 25, 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 isMetadataComment function lacks automated test coverage. Given that this function is critical for preventing metadata comments from entering the logical tree (which causes navigation errors), consider adding unit tests to verify:
- Correct identification of all metadata comment types (Blazor-Server-Component-State, Blazor-WebAssembly-Component-State, Blazor-Web-Initializers, Blazor-WebAssembly)
- Rejection of non-comment nodes
- Rejection of non-metadata comments (e.g., regular Blazor: component markers)
- Handling of whitespace variations in comment content
Example test structure:
describe('isMetadataComment', () => {
test('should identify server component state comments', () => {
const comment = document.createComment('Blazor-Server-Component-State:abc123');
expect(isMetadataComment(comment)).toBe(true);
});
test('should not identify component marker comments', () => {
const comment = document.createComment('Blazor:{"type":"server"}');
expect(isMetadataComment(comment)).toBe(false);
});
// ... more tests
});
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 metadata comment filtering logic in
toLogicalElementlacks automated test coverage. This is a critical fix for navigation errors, so consider adding tests to verify:Example test: