Skip to content

Commit c34376c

Browse files
committed
make sure we have unique USER id
* when a widget is created, make sure the user supplied id is unique, else we will have issues during load()/update()/etc...
1 parent 183885d commit c34376c

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

demo/two.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ <h1>Two grids demo</h1>
7575

7676
// sidebar content (just 2, rest is other behavior) to create when we get dropped, instead of inserting the clone version
7777
let sidebarContent = [
78-
{content: 'dropped'},
78+
{content: 'dropped', id: 'dup_id'}, // test to make sure unique ids are created when dropped mutliple times...
7979
{content: 'max=3', w:2, h:1, maxW: 3},
8080
];
8181

doc/CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Change log
55
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
66
**Table of Contents** *generated with [DocToc](http://doctoc.herokuapp.com/)*
77

8+
- [11.0.1 (2024-10-21)](#1101-2024-10-21)
89
- [11.0.0 (2024-10-20)](#1100-2024-10-20)
910
- [10.3.1 (2024-07-21)](#1031-2024-07-21)
1011
- [10.3.0 (2024-06-26)](#1030-2024-06-26)
@@ -114,6 +115,10 @@ Change log
114115

115116
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
116117

118+
## 11.0.1 (2024-10-21)
119+
* fix: [#2834](https://github.com/gridstack/gridstack.js/pull/2834) v11 angular missing package.json
120+
* fix: [#2835](https://github.com/gridstack/gridstack.js/bug/2835) make sure we have unique USER id
121+
117122
## 11.0.0 (2024-10-20)
118123
* feat: [#2826](https://github.com/gridstack/gridstack.js/pull/2826) Lazy loading of widget content until visible (`GridStackOptions.lazyLoad` and `GridStackWidget.lazyLoad`)
119124
* feat: [#2818](https://github.com/gridstack/gridstack.js/pull/2818) support for Angular Component hosting true sub-grids (that size according to parent) without requring them to be only child of grid-item-content.

src/gridstack-engine.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,15 @@ export class GridStackEngine {
352352
public prepareNode(node: GridStackNode, resizing?: boolean): GridStackNode {
353353
node._id = node._id ?? GridStackEngine._idSeq++;
354354

355+
// make sure USER supplied id are unique in our list, else assign a new one as it will create issues during load/update/etc...
356+
const id = node.id;
357+
if (id) {
358+
let count = 1; // append nice _n rather than some random number
359+
while (this.nodes.find(n => n.id === node.id && n !== node)) {
360+
node.id = id + '_' + (count++);
361+
}
362+
}
363+
355364
// if we're missing position, have the grid position us automatically (before we set them to 0,0)
356365
if (node.x === undefined || node.y === undefined || node.x === null || node.y === null) {
357366
node.autoPosition = true;

0 commit comments

Comments
 (0)