Skip to content

Commit 5868d21

Browse files
authored
fixed bug in Sections (#47870)
1 parent ed0309d commit 5868d21

File tree

4 files changed

+46
-4
lines changed

4 files changed

+46
-4
lines changed

src/Components/Components/src/Sections/SectionContent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Task IComponent.SetParametersAsync(ParameterView parameters)
7575
}
7676

7777
_registry.AddProvider(identifier, this, IsDefaultContent);
78-
_registeredIdentifier = SectionId;
78+
_registeredIdentifier = identifier;
7979
_registeredIsDefaultContent = IsDefaultContent;
8080
}
8181

src/Components/Components/src/Sections/SectionOutlet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Task IComponent.SetParametersAsync(ParameterView parameters)
6565
}
6666

6767
_registry.Subscribe(identifier, this);
68-
_subscribedIdentifier = SectionId;
68+
_subscribedIdentifier = identifier;
6969
}
7070

7171
RenderContent();

src/Components/test/E2ETest/Tests/SectionsTest.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,33 @@ public void RenderSectionContentWithSectionName_MatchingSectionOutletRendersCont
143143
Browser.Exists(By.Id("test6"));
144144
}
145145

146+
[Fact]
147+
public void SectionContentWithSectionNameGetsDisposed_OldSectionOutletNoLongerRendersContent()
148+
{
149+
_appElement.FindElement(By.Id("section-content-with-name")).Click();
150+
151+
Browser.Exists(By.Id("test6"));
152+
153+
_appElement.FindElement(By.Id("section-content-with-name-dispose")).Click();
154+
155+
Browser.DoesNotExist(By.Id("test6"));
156+
}
157+
158+
[Fact]
159+
public void SectionOutletWithSectionNameGetsDisposed_ContentDissapears()
160+
{
161+
// Render Counter and change its id so the content is rendered in second SectionOutlet
162+
_appElement.FindElement(By.Id("counter-render-section-content")).Click();
163+
164+
_appElement.FindElement(By.Id("counter-change-section-content-id")).Click();
165+
166+
Browser.Exists(By.Id("counter"));
167+
168+
_appElement.FindElement(By.Id("second-section-outlet-dispose")).Click();
169+
170+
Browser.DoesNotExist(By.Id("counter"));
171+
}
172+
146173
[Fact]
147174
public void RenderTwoSectionContentsWithSameSectionId_LastRenderedOverridesSectionOutletContent()
148175
{

src/Components/test/testassets/BasicTestApp/SectionsTest/ParentComponentWithTwoChildren.razor

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,27 @@
99

1010
<p>Text between two section outlets</p>
1111

12-
<SectionOutlet SectionName="@SecondSectionName" />
12+
@if (SecondSectionOutletExists)
13+
{
14+
<SectionOutlet SectionName="@SecondSectionName" />
15+
}
1316

1417
<p>Text between two section outlets</p>
1518

1619
<SectionOutlet SectionId="ThirdSectionName" />
1720

18-
1921
<button id="section-outlet-dispose"
2022
@onclick="@(() => FirstSectionOutletExists = false)">
2123
Dispose first SectionOutlet
2224
</button>
2325

26+
<br/>
27+
28+
<button id="second-section-outlet-dispose"
29+
@onclick="@(() => SecondSectionOutletExists = false)">
30+
Dispose second SectionOutlet
31+
</button>
32+
2433
@if (SectionOutletWithSameSectionIdExists)
2534
{
2635
<SectionOutlet SectionId="FirstSectionId" />
@@ -114,6 +123,11 @@
114123
Change SectionContent SectionName
115124
</button><br />
116125

126+
<button id="section-content-with-name-dispose"
127+
@onclick="@(() => SectionContentWithSectionNameExists = false)">
128+
Dispose SectionContent SectionName
129+
</button><br />
130+
117131
<Counter
118132
SectionContentExists="CounterSectionContentExists"
119133
SectionId="CounterSectionContentId">
@@ -164,6 +178,7 @@
164178

165179
@code {
166180
private bool FirstSectionOutletExists = true;
181+
private bool SecondSectionOutletExists = true;
167182
private bool SectionOutletWithSameSectionIdExists = false;
168183
private bool SectionOutletWithSameSectionNameExists = false;
169184
private bool SectionOutletWithEqualSectionNameToSectionIdExist = false;

0 commit comments

Comments
 (0)