dotnet/aspnetcore · error · Error

Could not find an end component comment for

Error message

Could not find an end component comment for '${start}'.

What it means

Thrown by getComponentEndComment after walking siblings of the start comment and finding no matching end comment for the given prerenderId. Prerendered components are bracketed by a start comment and an end comment carrying the same prerenderId; if the iterator exhausts siblings without the closing marker, the DOM is considered broken and discovery fails.

Solutions

  1. Inspect the served HTML: confirm both start and end Blazor comments are present and carry the same prerenderId.
  2. Disable any HTML post-processing that strips comments between prerender start and end.
  3. Ensure the full prerendered response is flushed (no truncation).
  4. Re-check that the component tree is balanced (no conditional that opens a marker without closing it).
  5. Align server and client runtime versions.
Defensive patterns

Strategy: validation

Validate before calling

function assertPairedMarkers(html: string) {
  const starts = (html.match(/<!--Blazor:[^{]*{"type"/g) || []).length;
  // end comments carry prerenderId only
  if (starts === 0) return;
  // ensure each start has a matching end by prerenderId (simplified)
}

Prevention

When it happens

Trigger: The <!--Blazor:{...prerenderId...}--> start marker exists but its matching end comment was removed, reordered, or never emitted; an HTML transformation split the component region; streaming SSR truncated before the end comment.

Common situations: HTML minifier/post-processor that drops 'redundant' comments; a partial render that emitted only the opening marker; a layout that conditionally renders and cuts the component boundary; caching that captured only part of the prerendered output.

Related errors


AI-assisted analysis of dotnet/aspnetcore@3600ca084e (2026-08-11). Data as JSON: /api/errors/ea5f2c7cd61c3266. Report an issue: GitHub.

Appendix: source

Thrown at src/Components/Web.JS/src/Services/ComponentDescriptorDiscovery.ts:211

    if (node.nodeType !== Node.COMMENT_NODE) {
      continue;
    }
    if (!node.textContent) {
      continue;
    }

    const definition = blazorCommentRegularExpression.exec(node.textContent);
    const json = definition && definition[1];
    if (!json) {
      continue;
    }

    validateEndComponentPayload(json, prerenderId);

    return node as Comment;
  }

  throw new Error(`Could not find an end component comment for '${start}'.`);
}

let nextUniqueDescriptorId = 0;

function createServerComponentComment(payload: ServerComponentMarker, start: Comment, end: Comment | undefined): ServerComponentDescriptor {
  validateServerComponentPayload(payload);

  return {
    ...payload,
    uniqueId: nextUniqueDescriptorId++,
    start,
    end,
  };
}

function createWebAssemblyComponentComment(payload: WebAssemblyComponentMarker, start: Comment, end: Comment | undefined): WebAssemblyComponentDescriptor {
  validateWebAssemblyComponentPayload(payload);

View on GitHub (pinned to 3600ca084e)