Skip to content

feat(DockView): add DockViewRenderMode.Partial parameter#957

Merged
ArgoZhang merged 13 commits intomasterfrom
feat-dockview
Mar 23, 2026
Merged

feat(DockView): add DockViewRenderMode.Partial parameter#957
ArgoZhang merged 13 commits intomasterfrom
feat-dockview

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Mar 23, 2026

Link issues

fixes #956

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Introduce a new partial render mode for DockView and wire up server-side and JavaScript logic to only render active or requested tabs.

New Features:

  • Add DockViewRenderMode.Partial to support partially rendering docked panels, rendering visible layouts immediately and non-visible layouts asynchronously.
  • Introduce LoadTabs callback plumbing between JavaScript and DockViewV2 to request which tabs should be rendered on the server.
  • Refactor DockViewComponent into a class-based component that renders its content conditionally based on DockView tab visibility.

Enhancements:

  • Default the DockView JavaScript renderer option and update panel/group config wiring to rely on the global renderer rather than per-panel renderer flags.
  • Extend dockview JavaScript utilities to track visible panels and notify .NET when active or visible tabs change, enabling optimized rendering behavior.

Copilot AI review requested due to automatic review settings March 23, 2026 04:06
@bb-auto bb-auto bot added the enhancement New feature or request label Mar 23, 2026
@bb-auto bb-auto bot added this to the v9.2.0 milestone Mar 23, 2026
@sourcery-ai
Copy link

sourcery-ai bot commented Mar 23, 2026

Reviewer's Guide

Adds a new DockViewRenderMode.Partial rendering mode and corresponding lazy/partial tab loading behavior by wiring Blazor components to new JS events, refactoring DockViewComponent into a code-only component that consults DockViewV2.ShowTab, and updating DockView/JS config and utilities to coordinate which tabs are rendered on the server based on client visibility state.

Sequence diagram for DockViewRenderMode.Partial tab loading

sequenceDiagram
    actor User
    participant Browser
    participant DockviewJS as Dockview_JS
    participant DotNet as DockViewV2_dotnet
    participant Component as DockViewComponent

    User->>Browser: Interact with dockview layout
    Browser->>DockviewJS: Dockview layout/visibility changes

    Note over DockviewJS: onDidLayoutFromJSON / onDidVisibilityChange

    DockviewJS->>DockviewJS: Compute visiblePanels keys
    DockviewJS->>DotNet: invokeMethodAsync(LoadTabs, tabs)

    DotNet->>DotNet: LoadTabs(tabs)
    DotNet->>DotNet: _loadTabs.Clear() then add each tab key
    DotNet->>DotNet: StateHasChanged()

    loop Render cycle
        DotNet->>Component: BuildRenderTree(builder)
        Component->>DotNet: DockView.ShowTab(Key)
        alt Renderer == Always
            DotNet-->>Component: true
        else Renderer == Partial or OnlyWhenVisible
            DotNet-->>Component: _loadTabs.Contains(Key)
        end
        alt ShowTab(Key) == true
            Component->>Component: Render ChildContent
        else ShowTab(Key) == false
            Component-->>Component: Skip ChildContent
        end
    end
Loading

Class diagram for DockView partial rendering and tab loading

classDiagram
    class DockViewComponentBase

    class DockViewComponent {
        +bool ShowTitleBar
        +string? TitleBarIcon
        +string? TitleBarIconUrl
        +string? Id
        +string? Key
        +string? Title
        +RenderFragment? TitleTemplate
        +RenderFragment? ChildContent
        +Func~Task~? OnClickTitleBarCallback
        -DockViewV2 DockView
        +void OnInitialized()
        +void BuildRenderTree(RenderTreeBuilder builder)
        -Task OnClickBar()
    }

    class DockViewV2 {
        -HashSet~string~ _loadTabs
        +DockViewRenderMode Renderer
        +Task LoadTabs(List~string~ tabs)
        +bool ShowTab(string? key)
        +Task PanelVisibleChangedCallbackAsync(string title, bool status)
    }

    class DockViewRenderMode {
        <<enumeration>>
        OnlyWhenVisible
        Always
        Partial
    }

    class DockViewConfig {
        +string? PanelVisibleChangedCallback
        +string? LockChangedCallback
        +string? SplitterCallback
        +string? LoadTabs
        +IEnumerable~DockViewComponent~ Contents
    }

    DockViewComponentBase <|-- DockViewComponent
    DockViewComponent ..> DockViewV2 : cascadingParameter
    DockViewV2 --> DockViewRenderMode : uses
    DockViewV2 --> DockViewConfig : configuredBy
    DockViewConfig o--> DockViewComponent : contents
Loading

File-Level Changes

Change Details Files
Refactor DockViewComponent into a non-razor component that conditionally renders its content based on the parent DockViewV2 ShowTab logic.
  • Change DockViewComponent from a partial .razor-backed component to a C# class inheriting DockViewComponentBase with an explicit BuildRenderTree implementation.
  • Inject DockViewV2 via CascadingParameter to allow checking whether a tab should be rendered.
  • Render the header area either via TitleTemplate or DockViewTitleBar when ShowTitleBar is true, then render ChildContent only when DockView.ShowTab(Key) returns true.
src/components/BootstrapBlazor.DockView/Components/DockViewComponent.cs
src/components/BootstrapBlazor.DockView/Components/DockViewComponent.razor
Introduce client-driven tab loading via LoadTabs callback and ShowTab API on DockViewV2 to support different render modes, including the new Partial mode.
  • Extend DockViewConfig with a LoadTabs callback name and pass it from DockViewV2 to JavaScript during initialization.
  • Add a JSInvokable LoadTabs(List tabs) method on DockViewV2 that tracks requested tab keys in a HashSet and triggers StateHasChanged.
  • Expose a ShowTab(string? key) method on DockViewV2 which always returns true for Always mode and otherwise checks the HashSet populated by LoadTabs.
src/components/BootstrapBlazor.DockView/Components/DockViewV2.razor.cs
src/components/BootstrapBlazor.DockView/Components/DockViewConfig.cs
src/components/BootstrapBlazor.DockView/Components/DockViewV2.razor.js
Extend the DockView render mode enumeration with a Partial option and synchronize it with new JavaScript renderer behaviors.
  • Add a Partial enum value to DockViewRenderMode with localized XML documentation.
  • Default the JS options.renderer to 'onlyWhenVisible' in dockview-utils.js and handle 'always', 'partial', and 'onlyWhenVisible' cases differently when laying out from JSON.
  • Wire a new 'loadTabs' JS event from the Dockview instance to the .NET LoadTabs callback, driving which tabs are rendered based on visibility and render mode.
src/components/BootstrapBlazor.DockView/Components/DockViewRenderMode.cs
src/components/BootstrapBlazor.DockView/wwwroot/js/dockview-utils.js
src/components/BootstrapBlazor.DockView/Components/DockViewV2.razor.js
Adjust dockview panel and configuration JavaScript to rely on the global renderer mode and visibility events instead of per-panel renderer configuration.
  • Stop propagating the per-contentItem renderer field into panel configurations in dockview-config.js and dockview-panel.js (comment out renderer assignment).
  • In dockview-panel.js, listen to panel.api.onDidVisibilityChange and, when using onlyWhenVisible mode and initialized, fire a loadTabs event for currently active/visible panels so .NET can render them.
  • Minor formatting tweaks in JS files (spacing/semicolons) without behavioral change aside from the new logic.
src/components/BootstrapBlazor.DockView/wwwroot/js/dockview-panel.js
src/components/BootstrapBlazor.DockView/wwwroot/js/dockview-config.js

Assessment against linked issues

Issue Objective Addressed Explanation
#956 Add a new DockViewRenderMode.Partial value to the DockViewRenderMode enum and expose it through the DockView configuration/options so it can be selected as a render mode.
#956 Implement the behavior for DockViewRenderMode.Partial so that DockView components support partial rendering (coordinated between Blazor and JS: tracking which tabs should be rendered, and conditionally rendering content based on that state).

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • In dockview-utils.js the if (options.renderer === 'always') {} branch is empty and several renderer assignments are commented out, which makes the behavior of the different render modes harder to follow; consider either implementing the always case explicitly or removing/commenting consistently so the effective behavior is clear.
  • The LoadTabs JS-invokable method clears _loadTabs and the JS code for the partial mode calls _loadTabs?.fire twice (once with visible panels and once with all panels), effectively discarding the first set; if this is not intentional, you may want to consolidate the calls or adjust LoadTabs so you don't overwrite the initially visible set.
  • In DockViewComponent.BuildRenderTree, DockView.ShowTab(Key) is used on a [CascadingParameter][NotNull] property; to make the component more robust against missing cascades or initialization-order issues, consider adding a null guard or fallback behavior rather than assuming DockView is always non-null at render time.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `dockview-utils.js` the `if (options.renderer === 'always') {}` branch is empty and several `renderer` assignments are commented out, which makes the behavior of the different render modes harder to follow; consider either implementing the `always` case explicitly or removing/commenting consistently so the effective behavior is clear.
- The `LoadTabs` JS-invokable method clears `_loadTabs` and the JS code for the `partial` mode calls `_loadTabs?.fire` twice (once with visible panels and once with all panels), effectively discarding the first set; if this is not intentional, you may want to consolidate the calls or adjust `LoadTabs` so you don't overwrite the initially visible set.
- In `DockViewComponent.BuildRenderTree`, `DockView.ShowTab(Key)` is used on a `[CascadingParameter][NotNull]` property; to make the component more robust against missing cascades or initialization-order issues, consider adding a null guard or fallback behavior rather than assuming `DockView` is always non-null at render time.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new DockView rendering mode (Partial) and introduces a JS→.NET “loadTabs” signal so the Blazor side can conditionally render panel content based on which tabs should be materialized.

Changes:

  • Add DockViewRenderMode.Partial and wire it through the DockView config/options.
  • Introduce a loadTabs event from JS to .NET ([JSInvokable] LoadTabs) and gate panel rendering via ShowTab.
  • Adjust JS initialization/visibility handling to request tab rendering via _loadTabs?.fire(...).

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/components/BootstrapBlazor.DockView/wwwroot/js/dockview-utils.js Sets default options.renderer; fires loadTabs during layout initialization
src/components/BootstrapBlazor.DockView/wwwroot/js/dockview-panel.js Fires loadTabs on panel visibility changes; changes how panel renderer is populated
src/components/BootstrapBlazor.DockView/wwwroot/js/dockview-config.js Changes how renderer is populated when rebuilding panels from config
src/components/BootstrapBlazor.DockView/Components/DockViewV2.razor.js Subscribes to loadTabs and forwards to .NET callback
src/components/BootstrapBlazor.DockView/Components/DockViewV2.razor.cs Adds LoadTabs JS-invokable + ShowTab gate
src/components/BootstrapBlazor.DockView/Components/DockViewComponent.cs Moves panel rendering to BuildRenderTree and gates by ShowTab
src/components/BootstrapBlazor.DockView/Components/DockViewComponent.razor Removed (logic moved into BuildRenderTree)
src/components/BootstrapBlazor.DockView/Components/DockViewRenderMode.cs Adds Partial enum value + doc updates
src/components/BootstrapBlazor.DockView/Components/DockViewConfig.cs Adds LoadTabs callback name to config
src/components/BootstrapBlazor.DockView/Components/DockViewV2.razor BOM/format-only change
src/components/BootstrapBlazor.DockView/BootstrapBlazor.DockView.csproj Package version updated from beta to stable
Comments suppressed due to low confidence (1)

src/components/BootstrapBlazor.DockView/Components/DockViewComponent.cs:182

  • BuildRenderTree no longer respects the component’s Visible parameter (previously @if (Visible) { @ChildContent }). As written, content can render even when Visible == false as soon as ShowTab(Key) is true, which is a behavior change and can lead to hidden/removed panels still rendering (and running) their child components. Consider gating content on both flags (e.g., Visible && DockView.ShowTab(Key)).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 278 to 283
title: item.title,
tabComponent: item.componentName,
contentComponent: item.componentName,
renderer: item.renderer || options.renderer,
// renderer: item.renderer || options.renderer,
params: { ...item, parentId: parent.id }
}
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as in dockview-panel.js: commenting out renderer: item.renderer || options.renderer means panels created from layout/config won’t carry a renderer value, but the rest of the JS uses panel.renderer to decide how to manage DOM/content. This likely causes inconsistent behavior when reloading layouts. Please restore setting renderer (or set a default elsewhere).

Copilot uses AI. Check for mistakes.
Comment on lines 303 to 309
panels[contentItem.id] = {
id: contentItem.id,
title: contentItem.title,
renderer: contentItem.renderer || options.renderer,
// renderer: contentItem.renderer || options.renderer,
tabComponent: contentItem.componentName,
contentComponent: contentItem.componentName,
params: { ...contentItem, parentId: parent.id }
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue as above: renderer is commented out for leaf panels, which can leave renderer undefined and break renderer-mode logic. Please ensure renderer is always set (e.g., contentItem.renderer || options.renderer).

Copilot uses AI. Check for mistakes.
Comment on lines +265 to +267
///
/// </summary>
/// <param name="tabs"></param>
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The XML doc for LoadTabs is empty and tabs parameter is undocumented. Given this is a JS-invokable public method that affects rendering, please add a clear summary (ideally bilingual if that’s the convention in this component) describing when JS calls it and what tabs contains.

Suggested change
///
/// </summary>
/// <param name="tabs"></param>
/// 标签页加载回调方法,由 JavaScript 在激活标签变化或需重新渲染时调用,用于更新当前需要渲染的标签集合。
/// Tab loading callback invoked from JavaScript when the set of active/visible tabs changes, updating which tabs should be rendered.
/// </summary>
/// <param name="tabs">
/// 需要在服务器端渲染的标签标识列表,由客户端脚本传入。每一项为一个标签的唯一标识。
/// List of tab identifiers that should currently be rendered on the server, provided by client-side script. Each item represents a single tab id.
/// </param>

Copilot uses AI. Check for mistakes.

/// <summary>
/// <para lang="zh">部分渲染 可见版面渲染 不可见版面异步渲染</para>
/// <para lang="en"></para>
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DockViewRenderMode.Partial has an empty English <para lang="en"> doc. Please fill it in to match the bilingual XML doc convention used for the rest of the enum values.

Suggested change
/// <para lang="en"></para>
/// <para lang="en">Partial rendering: render visible panels and asynchronously render invisible panels.</para>

Copilot uses AI. Check for mistakes.
const delPanelsStr = localStorage.getItem(dockview.params.options.localStorageKey + '-panels');
const delPanels = delPanelsStr && JSON.parse(delPanelsStr) || [];
if (options.renderer === 'always') {

Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

options.renderer === 'always' branch is empty. This conditional can be removed (and let the later branches handle the other modes) or implemented explicitly; leaving an empty branch makes the initialization logic harder to follow and suggests incomplete behavior.

Suggested change
if (dockview.panels.length > 0) {
dockview._loadTabs?.fire(dockview.panels.map(p => p.params.key));
}

Copilot uses AI. Check for mistakes.
groupId: contentItem.groupId,
title: contentItem.title,
renderer: contentItem.renderer || options.renderer,
// renderer: contentItem.renderer || options.renderer,
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renderer is no longer populated when building the panels list from options.content, but other code relies on panel.renderer (e.g., filtering onlyWhenVisible panels and passing renderer into dockview.addPanel). With this commented out, new panels created from options will have renderer === undefined, which can break render-mode behavior. Consider restoring renderer: contentItem.renderer || options.renderer (or otherwise ensuring a default is always set).

Suggested change
// renderer: contentItem.renderer || options.renderer,
renderer: contentItem.renderer || options.renderer,

Copilot uses AI. Check for mistakes.
@ArgoZhang ArgoZhang merged commit aa3c1b4 into master Mar 23, 2026
2 checks passed
@ArgoZhang ArgoZhang deleted the feat-dockview branch March 23, 2026 04:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(DockView): add DockViewRenderMode.Partial parameter

3 participants