diff --git a/src/Components/Components/src/Sections/SectionContent.cs b/src/Components/Components/src/Sections/SectionContent.cs index c2f722d9a566..6929434b4292 100644 --- a/src/Components/Components/src/Sections/SectionContent.cs +++ b/src/Components/Components/src/Sections/SectionContent.cs @@ -75,7 +75,7 @@ Task IComponent.SetParametersAsync(ParameterView parameters) } _registry.AddProvider(identifier, this, IsDefaultContent); - _registeredIdentifier = SectionId; + _registeredIdentifier = identifier; _registeredIsDefaultContent = IsDefaultContent; } diff --git a/src/Components/Components/src/Sections/SectionOutlet.cs b/src/Components/Components/src/Sections/SectionOutlet.cs index 34b89bd8ddf4..f8595f8f1d35 100644 --- a/src/Components/Components/src/Sections/SectionOutlet.cs +++ b/src/Components/Components/src/Sections/SectionOutlet.cs @@ -65,7 +65,7 @@ Task IComponent.SetParametersAsync(ParameterView parameters) } _registry.Subscribe(identifier, this); - _subscribedIdentifier = SectionId; + _subscribedIdentifier = identifier; } RenderContent(); diff --git a/src/Components/test/E2ETest/Tests/SectionsTest.cs b/src/Components/test/E2ETest/Tests/SectionsTest.cs index ab10f02da5ed..14766324bd13 100644 --- a/src/Components/test/E2ETest/Tests/SectionsTest.cs +++ b/src/Components/test/E2ETest/Tests/SectionsTest.cs @@ -143,6 +143,33 @@ public void RenderSectionContentWithSectionName_MatchingSectionOutletRendersCont Browser.Exists(By.Id("test6")); } + [Fact] + public void SectionContentWithSectionNameGetsDisposed_OldSectionOutletNoLongerRendersContent() + { + _appElement.FindElement(By.Id("section-content-with-name")).Click(); + + Browser.Exists(By.Id("test6")); + + _appElement.FindElement(By.Id("section-content-with-name-dispose")).Click(); + + Browser.DoesNotExist(By.Id("test6")); + } + + [Fact] + public void SectionOutletWithSectionNameGetsDisposed_ContentDissapears() + { + // Render Counter and change its id so the content is rendered in second SectionOutlet + _appElement.FindElement(By.Id("counter-render-section-content")).Click(); + + _appElement.FindElement(By.Id("counter-change-section-content-id")).Click(); + + Browser.Exists(By.Id("counter")); + + _appElement.FindElement(By.Id("second-section-outlet-dispose")).Click(); + + Browser.DoesNotExist(By.Id("counter")); + } + [Fact] public void RenderTwoSectionContentsWithSameSectionId_LastRenderedOverridesSectionOutletContent() { diff --git a/src/Components/test/testassets/BasicTestApp/SectionsTest/ParentComponentWithTwoChildren.razor b/src/Components/test/testassets/BasicTestApp/SectionsTest/ParentComponentWithTwoChildren.razor index 1d48ec85a868..d78d7021b640 100644 --- a/src/Components/test/testassets/BasicTestApp/SectionsTest/ParentComponentWithTwoChildren.razor +++ b/src/Components/test/testassets/BasicTestApp/SectionsTest/ParentComponentWithTwoChildren.razor @@ -9,18 +9,27 @@

Text between two section outlets

- +@if (SecondSectionOutletExists) +{ + +}

Text between two section outlets

- +
+ + + @if (SectionOutletWithSameSectionIdExists) { @@ -114,6 +123,11 @@ Change SectionContent SectionName
+
+ @@ -164,6 +178,7 @@ @code { private bool FirstSectionOutletExists = true; + private bool SecondSectionOutletExists = true; private bool SectionOutletWithSameSectionIdExists = false; private bool SectionOutletWithSameSectionNameExists = false; private bool SectionOutletWithEqualSectionNameToSectionIdExist = false;