Skip to content

fix(DockView): restore a re-shown group's size only when collapsed to its minimum#1051

Merged
ArgoZhang merged 2 commits into
masterfrom
fix-dockview-collapse-restore
Jun 26, 2026
Merged

fix(DockView): restore a re-shown group's size only when collapsed to its minimum#1051
ArgoZhang merged 2 commits into
masterfrom
fix-dockview-collapse-restore

Conversation

@zhaijunlei955

@zhaijunlei955 zhaijunlei955 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

#Issues
close #1052

Follow-up to #1047, which restored a re-opened group's width unconditionally and never restored height. In a left/right + nested (top/bottom) layout, re-showing a previously-closed group could then misbehave:

Problem

  • The opposite side goes blank: re-showing a group re-applied its stale saved width and shrank it; the freed space went to a sibling region that had no visible groups, so that whole side rendered blank (no content, though still draggable/operable).
  • Or the sibling gets squeezed to ~100px when the stale saved width was larger than the group's current width.
  • Vertical groups stuck at ~100px: groups in a top/bottom split came back at the minimum because height was never restored at all.

Fix

Restore a saved dimension (width and height) only when the group is actually collapsed to its minimum (offset <= group.minimum + 2); if the layout already gave it a real size, keep it.

.dv-view is an unstyled absolute wrapper, so its offset size equals the splitview size exactly — at collapse that is the group's minimum, making the check reliable.

Known limitation

Deleting both groups of one side in sequence then re-adding them can still squeeze one (the later-deleted group captured the full size while alone). Inherent to storing absolute sizes at delete time; a proportional / redistribute-on-re-add fix is deferred.

Summary by Sourcery

Adjust DockView group size restoration when re-showing previously closed groups to avoid layout issues in nested grid splits.

Bug Fixes:

  • Restore both width and height of re-shown groups only when they were previously collapsed to their minimum size, preventing sibling regions from being squeezed or rendered blank.
  • Ensure pending size state is cleared after a conditional size restore so future visibility changes do not replay stale dimensions.

Enhancements:

  • Add conditional logic for initial width and height when reusing empty grid groups based on current container size and group minimums.

@bb-auto

bb-auto Bot commented Jun 25, 2026

Copy link
Copy Markdown

Thanks for your PR, @zhaijunlei955. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@sourcery-ai

sourcery-ai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts how DockView restores panel group sizes when re-showing a previously deleted group, restoring saved width/height only when the placeholder group is actually collapsed to its minimum size and clearing pending sizes after use.

Sequence diagram for restoring DockView group size on re-show

sequenceDiagram
    participant DockView as dockview
    participant Group as group
    participant Panel as panel
    participant Parent as group_parent_element

    DockView->>Group: addPanelWidthGroupId(dockview, panel, index)
    Note over Group,Panel: reusedEmptyGroup && group.api.location.type === grid
    Group->>Parent: read offsetWidth, offsetHeight
    Group->>Panel: read params.currentPosition (cp.width, cp.height)
    alt [parent collapsed to minimum]
        Group->>DockView: set initialWidth = cp.width (if width > offsetWidth && offsetWidth <= minimumWidth + 2)
        Group->>DockView: set initialHeight = cp.height (if height > offsetHeight && offsetHeight <= minimumHeight + 2)
    else [parent has real size]
        Group->>DockView: leave initialWidth, initialHeight undefined
    end
    DockView->>Group: addPanel({ initialWidth, initialHeight, ... })
    Group->>Group: reRenderActionStates(group)
    Group->>Group: group.api._pendingSize = undefined (if initialWidth > 0 || initialHeight > 0)
Loading

Flow diagram for conditional restoration of DockView group width/height

flowchart TD
    A[reusedEmptyGroup && location.type === grid && parentElement exists] --> B[get cp.width, cp.height]
    B --> C[get parent offsetWidth, offsetHeight]
    C --> D{offsetWidth <= minimumWidth + 2\nand cp.width > offsetWidth}
    D -->|yes| E[initialWidth = cp.width]
    D -->|no| F[initialWidth undefined]
    C --> G{offsetHeight <= minimumHeight + 2\nand cp.height > offsetHeight}
    G -->|yes| H[initialHeight = cp.height]
    G -->|no| I[initialHeight undefined]
    E --> J[call dockview.addPanel with initialWidth/initialHeight]
    F --> J
    H --> J
    I --> J
    J --> K{initialWidth > 0 or initialHeight > 0}
    K -->|yes| L[group.api._pendingSize = undefined]
    K -->|no| M[leave _pendingSize unchanged]
Loading

File-Level Changes

Change Details Files
Restore saved width and height for reused grid groups only when the placeholder is collapsed to its minimum size, and clear pending sizes after the restore.
  • Replace single restoreWidth calculation with logic that conditionally sets initialWidth and initialHeight based on the parent element’s offset size and the group’s minimum size thresholds.
  • Use both initialWidth and initialHeight when adding a panel to a reused empty group, instead of restoring width unconditionally.
  • Update the post-restore cleanup to clear group.api._pendingSize when either width or height was restored, so stale sizes are not replayed later.
src/components/BootstrapBlazor.DockView/wwwroot/js/dockview-group.js

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

@bb-auto bb-auto Bot requested a review from ArgoZhang June 25, 2026 12:12

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

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:

  • The + 2 tolerance when comparing offsetWidth/offsetHeight to minimumWidth/Height is a bit opaque; consider extracting this into a named constant or helper to document the rationale and keep the magic number in one place.
  • The reusedEmptyGroup && group.api.location.type === 'grid' guard is now used in two places; consider centralizing the grid-specific reuse logic into a small helper to avoid duplicating conditions and keep behavior changes localized.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `+ 2` tolerance when comparing `offsetWidth/offsetHeight` to `minimumWidth/Height` is a bit opaque; consider extracting this into a named constant or helper to document the rationale and keep the magic number in one place.
- The `reusedEmptyGroup && group.api.location.type === 'grid'` guard is now used in two places; consider centralizing the grid-specific reuse logic into a small helper to avoid duplicating conditions and keep behavior changes localized.

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.

@bb-auto bb-auto Bot added the enhancement New feature or request label Jun 26, 2026
@bb-auto bb-auto Bot added this to the v10.0.0 milestone Jun 26, 2026
@ArgoZhang ArgoZhang merged commit a7e2671 into master Jun 26, 2026
3 checks passed
@ArgoZhang ArgoZhang deleted the fix-dockview-collapse-restore branch June 26, 2026 03:47
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.

fix(DockView): restore a re-shown group's size only when collapsed to its minimum

2 participants