Repository: dotnet/aspnetcore
File: src/Components/Endpoints/src/Rendering/EndpointHtmlRenderer.Prerendering.cs (C#)

Code before:
    {
        if (!httpContext.Items.TryGetValue(ComponentSequenceKey, out var result))
        {
            result = new ServerComponentInvocationSequence();
            httpContext.Items[ComponentSequenceKey] = result;
        }

        return (ServerComponentInvocationSequence)result!;
    }

    internal (int sequence, object? key) GetSequenceAndKey(ComponentState boundaryComponentState)
    {
        if (boundaryComponentState is null || boundaryComponentState.Component is not SSRRenderModeBoundary boundary)
        {
            throw new InvalidOperationException(
                "The parent component state must be an SSRRenderModeBoundary to get the sequence and key.");
        }

        // The boundary is at the root (not supported, but we handle it gracefully)
        if (boundaryComponentState.ParentComponentState is null)
        {
            return (0, null);
        }

        // Grab the parent of the boundary component. We need to find the SSRRenderModeBoundary component marker frame
        // within it. AS when we do `@rendermode="InteractiveServer" @key="some-key" the sequence we are interested in
        // is the one on the SSRRenderModeBoundary component marker frame, not the one on the nested component frame.
        // Same for the key.
        var targetState = boundaryComponentState.ParentComponentState;
        var frames = GetCurrentRenderTreeFrames(targetState.ComponentId);
        for (var i = 0; i < frames.Count; i++)
        {
            ref var frame = ref frames.Array[i];
            if (frame.FrameType == RenderTreeFrameType.Component &&
                frame.Component is SSRRenderModeBoundary candidate &&
                ReferenceEquals(candidate, boundary))
            {
                // This is the component marker frame, so we can use its sequence and key
                return (frame.Sequence, frame.ComponentKey);
            }
        }

        throw new InvalidOperationException(
            "The parent component state does not have a valid SSRRenderModeBoundary component marker frame.");
    }

    // An implementation of IHtmlContent that holds a reference to a component until we're ready to emit it as HTML to the response.
    // We don't construct the actual HTML until we receive the call to WriteTo.
    public class PrerenderedComponentHtmlContent : IHtmlAsyncContent
    {
        private readonly Dispatcher? _dispatcher;

Review comment (suggestion):
```suggestion
        // within it. As when we do `@rendermode="InteractiveServer" @key="some-key" the sequence we are interested in
```

Code after:
    {
        if (!httpContext.Items.TryGetValue(ComponentSequenceKey, out var result))
        {
            result = new ServerComponentInvocationSequence();
            httpContext.Items[ComponentSequenceKey] = result;
        }

        return (ServerComponentInvocationSequence)result!;
    }

    internal (int sequence, object? key) GetSequenceAndKey(ComponentState boundaryComponentState)
    {
        if (boundaryComponentState is null || boundaryComponentState.Component is not SSRRenderModeBoundary boundary)
        {
            throw new InvalidOperationException(
                "The parent component state must be an SSRRenderModeBoundary to get the sequence and key.");
        }

        // The boundary is at the root (not supported, but we handle it gracefully)
        if (boundaryComponentState.ParentComponentState is null)
        {
            return (0, null);
        }

        // Grab the parent of the boundary component. We need to find the SSRRenderModeBoundary component marker frame
        // within it. As when we do `@rendermode="InteractiveServer" @key="some-key" the sequence we are interested in
        // is the one on the SSRRenderModeBoundary component marker frame, not the one on the nested component frame.
        // Same for the key.
        var targetState = boundaryComponentState.ParentComponentState;
        var frames = GetCurrentRenderTreeFrames(targetState.ComponentId);
        for (var i = 0; i < frames.Count; i++)
        {
            ref var frame = ref frames.Array[i];
            if (frame.FrameType == RenderTreeFrameType.Component &&
                frame.Component is SSRRenderModeBoundary candidate &&
                ReferenceEquals(candidate, boundary))
            {
                // This is the component marker frame, so we can use its sequence and key
                return (frame.Sequence, frame.ComponentKey);
            }
        }

        throw new InvalidOperationException(
            "The parent component state does not have a valid SSRRenderModeBoundary component marker frame.");
    }

    // An implementation of IHtmlContent that holds a reference to a component until we're ready to emit it as HTML to the response.
    // We don't construct the actual HTML until we receive the call to WriteTo.
    public class PrerenderedComponentHtmlContent : IHtmlAsyncContent
    {
        private readonly Dispatcher? _dispatcher;