Skip to content

NaN inf loop when using cellHeight rem/em #2361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ Change log
## 8.2.1-dev (TBD)
* fix [#2349](https://github.com/gridstack/gridstack.js/issues/2349) grid NoMove vs item NoMove support
* fix [#2352](https://github.com/gridstack/gridstack.js/issues/2352) .ui-draggable-dragging z-index for modal dialogs
* fix [#2357](https://github.com/gridstack/gridstack.js/issues/2357) NaN inf loop when using cellHeight rem/em

## 8.2.1 (2023-05-26)
* fix: make sure `removeNode()` uses internal _id (unique) and not node itself (since we clone those often)
Expand Down
23 changes: 23 additions & 0 deletions spec/e2e/html/2357_rem.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<head>
<title>REM demo</title>
<link rel="stylesheet" href="../../../demo.css"/>
<script src="../../../dist/gridstack-all.js"></script>
</head>
<body>
<div class="grid-stack"></div>
<script type="text/javascript">
let items = [
{x: 0, y: 0},
{x: 1, y: 0},
];
let count = 0;
items.forEach(d => d.content = String(count++));

let grid = GridStack.init({
// cellHeight: '90',
cellHeight: '8rem',
}).load(items);
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion src/gridstack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ export class GridStack {
// else get first cell height
let el = this.el.querySelector('.' + this.opts.itemClass) as HTMLElement;
if (el) {
let height = Utils.toNumber(el.getAttribute('gs-h'));
let height = Utils.toNumber(el.getAttribute('gs-h')) || 1; // since we don't write 1 anymore
return Math.round(el.offsetHeight / height);
}
// else do entire grid and # of rows (but doesn't work if min-height is the actual constrain)
Expand Down