Skip to content

Commit 6f7a056

Browse files
committed
resizeToContent JS error with nested grid
1 parent 4d50367 commit 6f7a056

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

doc/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ Change log
115115

116116
## 10.3.0-dev (TBD)
117117
* fix: [#2734](https://github.com/gridstack/gridstack.js/bug/2734) rotate() JS error
118+
* fix: [#2739](https://github.com/gridstack/gridstack.js/pull/2739) resizeToContent JS error with nested grid
118119

119120
## 10.3.0 (2024-06-26)
120121
* fix: [#2720](https://github.com/gridstack/gridstack.js/pull/2720) load() now creates widgets in order (used to be reverse due to old collision code)

src/gridstack.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1401,10 +1401,16 @@ export class GridStack {
14011401
if (n.subGrid) {
14021402
// sub-grid - use their actual row count * their cell height
14031403
wantedH = n.subGrid.getRow() * n.subGrid.getCellHeight(true);
1404+
} else if (n.subGridOpts?.children?.length) {
1405+
// not sub-grid just yet (case above) wait until we do
1406+
return;
14041407
} else {
14051408
// NOTE: clientHeight & getBoundingClientRect() is undefined for text and other leaf nodes. use <div> container!
14061409
const child = item.firstElementChild;
1407-
if (!child) { console.error(`Error: GridStack.resizeToContent() widget id:${n.id} '${GridStack.resizeToContentParent}'.firstElementChild is null, make sure to have a div like container. Skipping sizing.`); return; }
1410+
if (!child) {
1411+
console.error(`Error: GridStack.resizeToContent() widget id:${n.id} '${GridStack.resizeToContentParent}'.firstElementChild is null, make sure to have a div like container. Skipping sizing.`);
1412+
return;
1413+
}
14081414
wantedH = child.getBoundingClientRect().height || itemH;
14091415
}
14101416
if (itemH === wantedH) return;

0 commit comments

Comments
 (0)