Skip to content

fix: incorrect node._id check #3077

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
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
2 changes: 1 addition & 1 deletion src/gridstack-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ export class GridStackEngine {
// remember it's position & width so we can restore back (1 -> 12 column) #1655 #1985
// IFF we're not in the middle of column resizing!
const saveOrig = (node.x || 0) + (node.w || 1) > this.column;
if (saveOrig && this.column < this.defaultColumn && !this._inColumnResize && !this.skipCacheUpdate && (node._id ?? false) && this.findCacheLayout(node, this.defaultColumn) === -1) {
if (saveOrig && this.column < this.defaultColumn && !this._inColumnResize && !this.skipCacheUpdate && node._id != null && this.findCacheLayout(node, this.defaultColumn) === -1) {
Copy link
Member

@adumesny adumesny Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_id is internal to me, so it should always be set, or undefined. weird that you are checking (and should be !== null).
I would have to check why it isn't set (and why null works in your case ?
maybe I can start _id at 1 instead...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is set, its just that a _id of 0 leads to it being falsy again as my earlier code was wrong. != null just checks that its not null or undefined. If its never going to be null !== undefined would work fine as well
image

const copy = {...node}; // need _id + positions
if (copy.autoPosition || copy.x === undefined) { delete copy.x; delete copy.y; }
else copy.x = Math.min(this.defaultColumn - 1, copy.x);
Expand Down