You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Widget width reported incorrectly by save() after dragging from wider nested grid #2394
Widget width is incorrect in JSON produced by the save() method, if the given widget has been dragged from a nested grid that has more columns than the outer grid. The grid and widgets behave correctly, the problem is only with data generated by save(). Loading back this data into the grid will cause an incorrect state (since the JSON contains an impossible layout)
ha, good catch. ._layouts has higher resolution column count so we tend to save from that (say 12 -> 1 then save should remember the 12 column full layout not 1 column layout). the bug here is that when moving an item to another grid (parent) we don't delete those entries. I'm actually surprised we use _layouts from another grid essentially...
The comment at line 389 mentions my use case (the "target" grid has fewer columns than the "source" nested grid). I created a fork where I remove the added nodes from the layout cache when an add event is triggered. I'm not sure if this could cause issues in other use cases, but the width is reported correctly for me after this. https://github.com/gridstack/gridstack.js/compare/master...akosfekete:gridstack.js:2394_fix?expand=1
Activity
adumesny commentedon Jul 17, 2023
ha, good catch.
._layoutshas higher resolution column count so we tend to save from that (say 12 -> 1 then save should remember the 12 column full layout not 1 column layout). the bug here is that when moving an item to another grid (parent) we don't delete those entries. I'm actually surprised we use _layouts from another grid essentially...akosfekete commentedon Sep 13, 2023
The issue seems to stem from
nodeBoundFix (), where the layout is cached as you mentioned: https://github.com/gridstack/gridstack.js/blob/768b8ef6c508c6c47ad44c0748f0f11405da4716/src/gridstack-engine.ts#L398C37-L398C37The comment at line 389 mentions my use case (the "target" grid has fewer columns than the "source" nested grid). I created a fork where I remove the added nodes from the layout cache when an add event is triggered. I'm not sure if this could cause issues in other use cases, but the width is reported correctly for me after this.
https://github.com/gridstack/gridstack.js/compare/master...akosfekete:gridstack.js:2394_fix?expand=1
better fix: nested grid size issue