Skip to content

fix: SectionOutlet in Navigation area throws "There is already a subscriber" when resizing across the mobile breakpoint #5115

Description

@Asttear

🐛 Bug Report

FluentLayout.NavigationDeferredLoading="true" + a SectionOutlet in the LayoutArea.Navigation item crashes with There is already a subscriber to the content with the given section ID when the window is resized across the 768px mobile breakpoint.

💻 Repro or Code Sample

MainLayout.razor (drop into any FluentUI v5 Blazor app — or simply add a SectionOutlet to the LayoutArea.Navigation item of the FluentUI demo's DemoMainLayout, which already uses NavigationDeferredLoading="true"):

@inherits LayoutComponentBase

<FluentLayout NavigationDeferredLoading="true">
    <FluentLayoutItem Area="@LayoutArea.Header">
        <FluentStack VerticalAlignment="VerticalAlignment.Center">
            <FluentLayoutHamburger Display="@HamburgerDisplay.DesktopMobile" />
            <SectionOutlet SectionName="topbar" />
        </FluentStack>
    </FluentLayoutItem>

    <FluentLayoutItem Area="@LayoutArea.Navigation" Width="300px">
        <SectionOutlet SectionName="sidebar" />
    </FluentLayoutItem>

    <FluentLayoutItem Area="@LayoutArea.Content">@Body</FluentLayoutItem>
</FluentLayout>

A page provides the content:

<SectionContent SectionName="sidebar">
    <div>Some sidebar content</div>
</SectionContent>

Steps to reproduce:

  1. Run the app at a desktop window width (e.g. 1280px).
  2. Resize the window below the 768px mobile breakpoint — or back across it.

🤔 Expected Behavior

The layout adapts to the mobile viewport without error. The inline Navigation item and the hamburger drawer should render mutually exclusively across the breakpoint change.

😯 Current Behavior

Resizing throws an unhandled exception (crashes the app):

System.InvalidOperationException: There is already a subscriber to the content with the given section ID 'System.Object'.
   at Microsoft.AspNetCore.Components.Sections.SectionRegistry.Subscribe(Object identifier, SectionOutlet subscriber)
   at Microsoft.AspNetCore.Components.Sections.SectionOutlet.Microsoft.AspNetCore.Components.IComponent.SetParametersAsync(ParameterView parameters)
   at Microsoft.AspNetCore.Components.Rendering.ComponentState.SupplyCombinedParameters(...)

The section ID string shown depends on the identifier used — SectionName shows the name; a SectionId object shows its ToString().

💁 Possible Solution

FluentLayoutHamburger.NavigationContent defaults to the Navigation area's ChildContent:

NavigationContent => ChildContent ?? LayoutContainer?.Areas.Find(i => i.Area == LayoutArea.Navigation)?.ChildContent

On a breakpoint flip, FluentLayout.FluentLayout_MediaChangedAsync refreshes hamburgers before Navigation-area items, as two separate render batches:

foreach (var item in Hamburgers) await item.RefreshAsync();
foreach (var item in Areas.Where(i => i.Area == LayoutArea.Navigation)) await item.RefreshAsync();

With NavigationDeferredLoading="true", crossing the breakpoint flips RenderDrawer() (hamburger) and RenderThisArea() (nav item) in opposite directions. Because the hamburger renders first, the drawer's mirrored NavigationContent instantiates a second SectionOutlet with the same section ID while the nav item's outlet is still subscribed → SectionRegistry.Subscribe throws.

Suggested fix: refresh the Navigation-area items before the hamburgers in FluentLayout_MediaChangedAsync (so the old outlet unsubscribes before the drawer's mirror subscribes), or otherwise make the inline-nav / drawer-in-drawer rendering mutually exclusive within a single render batch. Happy to open a PR if the ordering approach is acceptable.

🔦 Context

Desktop tool whose page feeds a sidebar through SectionOutlet/SectionContent. The window is resizable; shrinking it across the 768px breakpoint (or back) crashes the whole app, making the layout unusable on smaller windows.

🌍 Your Environment

  • OS & Device: Windows 11 on PC
  • Browser: Edge WebView2 (Blazor WebView / Hybrid host)
  • .NET and Fluent UI Blazor library Version: .NET 10.0, Microsoft.FluentUI.AspNetCore.Components 5.0.0-rc.4-26180.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    triageNew issue. Needs to be looked at

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions