Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Components/Web.JS/src/Rendering/LogicalElements.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

import { ComponentDescriptor } from '../Services/ComponentDescriptorDiscovery';
import { ComponentDescriptor, isMetadataComment } from '../Services/ComponentDescriptorDiscovery';

/*
A LogicalElement plays the same role as an Element instance from the point of view of the
Expand Down Expand Up @@ -109,6 +109,12 @@ export function toLogicalElement(element: Node, allowExistingContents?: boolean)
}

element.childNodes.forEach(child => {
// Skip metadata comments that will be consumed during discovery
// These are not components and should not be part of the logical tree
if (isMetadataComment(child)) {
return;
}

const childLogicalElement = toLogicalElement(child, /* allowExistingContents */ true);
childLogicalElement[logicalParentPropname] = element;
childrenArray.push(childLogicalElement);
Expand Down
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:');
}

export function discoverComponents(root: Node, type: 'webassembly' | 'server' | 'auto'): ComponentDescriptor[] {
switch (type) {
case 'webassembly':
Expand Down
Loading