dockview icon indicating copy to clipboard operation
dockview copied to clipboard

Inconsistent minimumHeight after refresh when using setConstraints

Open zengyumei opened this issue 9 months ago • 1 comments

Describe the bug

  1. When setting panel constraints via group.api.setConstraints({ minimumHeight: 50 }), the minimum height works correctly during runtime but reverts to the default 100px after page refresh. This occurs because addPanel uses a default minimumHeight: 100px if not explicitly provided, overriding the dynamically set constraint.
  2. When initial constraints are set via addPanel parameters (e.g., minimumHeight: 200), subsequent calls to panelGroup.api.setConstraints({ minimumHeight: 50 }) fail to override the initial values. This creates an irreversible constraint configuration where dynamic constraint updates are ignored.

To Reproduce https://codesandbox.io/p/sandbox/dawn-glade-8xq494

Steps to reproduce the behavior: For the first question:

  1. Add a panel without specifying minimumHeight minimumWidth :
props.api.addPanel({
    id: 'panel_1',
    component: 'default',
});
  1. Set constraints:
props.api.group.api.setConstraints({
    minimumWidth: 50,
    minimumHeight: 50,
});
  1. Resize the panel vertically - it correctly respects 50px minimum.
  2. Refresh the page - the panel height jumps to 100px.

For the second question: 1.Add panel with initial constraints:

props.api.addPanel({
    id: 'panel_1',
    component: 'default',
    minimumWidth: 200, // initial minimumWidth
});
  1. Set constraints:
props.api.group.api.setConstraints({
    minimumWidth: 50,
    minimumHeight: 50,
});
  1. Observe panel still enforces 200px minimum height

Expected behavior

  1. The minimumHeight set via setConstraints should persist after refresh, or at least not be overridden by the default 100px value from addPanel
  2. The setConstraints API should always take precedence over initial values set in addPanel, allowing runtime constraint adjustments regardless of initialization parameters.

Technical Analysis The constraint system appears to have this priority order: addPanel parameters > setConstraints > group defaults When it should be: Active setConstraints > addPanel parameters > group defaults

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • Browser: Chrome 131
  • macOS : 14.2

Additional context The issue arises because addPanel defaults minimumHeight to 100px. When the layout reinitializes after refresh, it uses this default value instead of the dynamically set constraint.

Expected resolution: Either: Allow setConstraints to override the default values permanently, or Make addPanel inherit constraints set via setConstraints during initialization.

zengyumei avatar Mar 10 '25 09:03 zengyumei

same issue

chhsgithub avatar Apr 03 '25 04:04 chhsgithub

This does seem to be expected behavior right now, per the docs:

Constraints come with several caveats. They are not serialized with layouts and can only be applied to groups.

But the default constraints are arbitrary and much too large in my case. If anything, I'd suggest using the tab height as the default minimum height, so you can always see the tab even if the body has a height of 0.

It might help a if there were a way to set the default constraints (e.g. before deserializing a saved layout). But of course, actually serializing the constraints in JSON would be better.

What I don't understand is why this code in the panel deserializer is attempting to read constraints from the panel JSON, when the constraint API clearly only applies to panel groups. Seems to me that panelData.minimumWidth would always be undefined.

Really, I think we should support constraints on panels, and the group automatically adopts these constraints. Here is what I do in my application: I manually add min_height to my panel params (which are user-defined). Then, I have an event handler for api.onDidLayoutChange() which does the following:

/**
 * Set size constraints for each panel group based on the minimums of its child panels.
 */
function update_group_size_constraints(dockview_api: DockviewApi) {
  for (let group of dockview_api.groups) {
    const group_min_height = group.panels.reduce((group_min_height, panel) => {
      return Math.max(group_min_height, panel.params?.min_height ?? DOCKVIEW_TAB_HEIGHT);
    }, 0);
    group.api.setConstraints({
      minimumHeight: group_min_height,
    });
  }
}

The problem is that if I load a saved layout, even if I run this function the layout has already been messed up by applying the default constraints.

Intuitively I think constraints should be configured on individual panels. Maybe it's still useful to have constraints on groups as well, in which case ideally both sets of constraints would apply (unless they conflict, in which case maybe the group wins?)

mpearson avatar May 01 '25 19:05 mpearson

A fix for this is in 4.11.0. If issues are found I will reopen

mathuo avatar Nov 04 '25 22:11 mathuo