Skip to content
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

Infinite Loop, browser freeze when using autoPosition: true, resizing columns #2406

Closed
ExusAltimus opened this issue Aug 8, 2023 · 3 comments · Fixed by #2408
Closed

Infinite Loop, browser freeze when using autoPosition: true, resizing columns #2406

ExusAltimus opened this issue Aug 8, 2023 · 3 comments · Fixed by #2408
Labels

Comments

@ExusAltimus
Copy link

Subject of the issue

I am adding widgets to the grid (autoPosition:true) and have the ability to resize the columns.
The resizing columns may not be necessary to reproduce this bug but I'm showing the scenario in which I encountered it
When I add a widget, resize the columns, then add another widget, the application / browser window crashes completely
I noticed when not using autoPosition that it behaved normally

Your environment

Gridstack version: 8.4.0
Chrome / Edge / Firefox

Steps to reproduce

Click add widget, then click resize column, then add another widget, browser should freeze
https://jsfiddle.net/zsm039xo/7/

Expected behavior

The infinite loop is caused by findEmptyPosition, the real scope of the issue may extend beyond this function

    for (let i = start; !found; ++i) {
      let x = i % column;
      let y = Math.floor(i / column);
      if (x + node.w > column) {
        continue;
      }
      let box = {x, y, w: node.w, h: node.h};
      if (!nodeList.find(n => Utils.isIntercepted(box, n))) {
        if (node.x !== x || node.y !== y) node._dirty = true;
        node.x = x;
        node.y = y;
        delete node.autoPosition;
        found = true;
      }
    }
    return found;
  }
@adumesny
Copy link
Member

adumesny commented Aug 11, 2023

your example is missing extra.css (to show 2 columns) but I see the inf loop.
actaully there are tons of issue I see with v8.4 not just autoposition but 1 column loading as well... sight.
thanks
https://jsfiddle.net/adumesny/2z1f6x8w/

adumesny added a commit to adumesny/gridstack.js that referenced this issue Aug 11, 2023
* this was a very particular flow where autoPosition were loading into 1 column (so we save the higher grid count layout) then switch to 2 column, then loaded new items.
* also fixed new v9 issue with sizing called with column 1 already.
adumesny added a commit that referenced this issue Aug 11, 2023
#2406 inf loop fix adding autoPosition in 1->2 column
@adumesny
Copy link
Member

fixed in next release. don't forget to donate if you find this lib useful!

@ExusAltimus
Copy link
Author

Thank you so much for the speedy response / fix. I'll surely send a dontation as I have found it extremely useful. Keep up the good work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants