Skip to content

Commit 158d048

Browse files
Fix misdetection of component comments (#52647) (#52744)
1 parent a07fe32 commit 158d048

File tree

8 files changed

+76
-7
lines changed

8 files changed

+76
-7
lines changed

src/Components/Web.JS/dist/Release/blazor.server.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Components/Web.JS/dist/Release/blazor.web.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Components/Web.JS/dist/Release/blazor.webview.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Components/Web.JS/src/Rendering/LogicalElements.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,13 @@ export function insertLogicalChildBefore(child: Node, parent: LogicalElement, be
149149
export function insertLogicalChild(child: Node, parent: LogicalElement, childIndex: number): void {
150150
const childAsLogicalElement = child as unknown as LogicalElement;
151151

152-
// If the child is a component comment with logical siblings, its siblings also
152+
// If the child is a component comment with logical children, its children
153153
// need to be inserted into the parent node
154154
let nodeToInsert = child;
155-
if (isLogicalElement(child)) {
156-
const lastNodeToInsert = findLastDomNodeInRange(childAsLogicalElement);
157-
if (lastNodeToInsert !== child) {
155+
if (child instanceof Comment) {
156+
const existingGranchildren = getLogicalChildrenArray(childAsLogicalElement);
157+
if (existingGranchildren?.length > 0) {
158+
const lastNodeToInsert = findLastDomNodeInRange(childAsLogicalElement);
158159
const range = new Range();
159160
range.setStartBefore(child);
160161
range.setEndAfter(lastNodeToInsert);

src/Components/test/E2ETest/ServerRenderingTests/StreamingRenderingTest.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,4 +316,37 @@ public async Task WorksWithVeryBriefStreamingDelays()
316316
Assert.Matches(new Regex(@"</html><!--[0-9a-f\-]{36}--><blazor-ssr>"), html);
317317
}
318318
}
319+
320+
// https://github.com/dotnet/aspnetcore/issues/52126
321+
[Fact]
322+
public void CanPerformEnhancedNavigation_AfterStreamingUpdate_WithInteractiveComponentInLayout()
323+
{
324+
Navigate($"{ServerPathBase}/interactive-in-layout/streaming");
325+
326+
Browser.Exists(By.Id("done-streaming"));
327+
Browser.Equal("True", () => Browser.FindElement(By.Id("is-interactive-counter")).Text);
328+
Browser.Click(By.Id("increment-counter"));
329+
Browser.Equal("1", () => Browser.FindElement(By.Id("count-counter")).Text);
330+
331+
Browser.Click(By.LinkText("Non-streaming"));
332+
Browser.Exists(By.Id("non-streamed-content"));
333+
334+
Browser.Click(By.Id("increment-counter"));
335+
Browser.Equal("2", () => Browser.FindElement(By.Id("count-counter")).Text);
336+
337+
AssertLogDoesNotContainCriticalMessages("DOMException");
338+
}
339+
340+
private void AssertLogDoesNotContainCriticalMessages(params string[] messages)
341+
{
342+
var log = Browser.Manage().Logs.GetLog(LogType.Browser);
343+
foreach (var message in messages)
344+
{
345+
Assert.DoesNotContain(log, entry =>
346+
{
347+
return entry.Level == LogLevel.Severe
348+
&& entry.Message.Contains(message);
349+
});
350+
}
351+
}
319352
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@inherits LayoutComponentBase
2+
3+
<NavLink href="interactive-in-layout/streaming">Streaming</NavLink>
4+
<NavLink href="interactive-in-layout/non-streaming">Non-streaming</NavLink>
5+
6+
@* https://github.com/dotnet/aspnetcore/issues/52126 *@
7+
<TestContentPackage.Counter IdSuffix="counter" IncrementAmount="1" @rendermode="RenderMode.InteractiveServer" />
8+
9+
@Body
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@layout LayoutWithInteractiveComponent
2+
@page "/interactive-in-layout/non-streaming"
3+
4+
<h3>Non-streaming</h3>
5+
6+
<p id="non-streamed-content">Non-streamed content</p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
@layout LayoutWithInteractiveComponent
2+
@page "/interactive-in-layout/streaming"
3+
@attribute [StreamRendering]
4+
5+
<h3>Streaming</h3>
6+
7+
@if (_doneStreaming)
8+
{
9+
<p id="done-streaming">Done streaming!</p>
10+
}
11+
12+
@code {
13+
bool _doneStreaming;
14+
15+
protected override async Task OnInitializedAsync()
16+
{
17+
await Task.Delay(200);
18+
_doneStreaming = true;
19+
}
20+
}

0 commit comments

Comments
 (0)