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

fix issue on failed drag makes the whole grid unresponsive #2672

Merged
merged 2 commits into from
May 16, 2024

Conversation

mustafamilyas
Copy link
Contributor

@mustafamilyas mustafamilyas commented May 2, 2024

Description

Screenshot 2024-05-02 at 09 16 45
when we drag a widget and fail, it will throw the above error and make all the whole grid unresponsive

Checklist

  • Created tests which fail without the change (if possible)
  • All tests passing (yarn test)
  • Extended the README / documentation, if necessary

How to reproduce

  • Enable dragging a widget from outside onto the grid.
  • Ensure the grid is crowded, leaving very little space (less than the size of the widget).
  • Drag the widget into that small space.

Comment on lines +114 to +116
return n?.grid && (strict ?
(n.sizeToContent === true || (n.grid.opts.sizeToContent === true && n.sizeToContent === undefined)) :
(!!n.sizeToContent || (n.grid.opts.sizeToContent && n.sizeToContent !== false)));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

when I run the test script, it fails, and this is the result when I run yarn test --fix

Copy link
Member

Choose a reason for hiding this comment

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

that's just reformatting (yarn lint --fix) not yarn test.... humm.

Copy link
Member

@adumesny adumesny May 2, 2024

Choose a reason for hiding this comment

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

You didn't provide an example showing the drag failing so can't reproduce. hard to tell if this is the right fix without digging into it more.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apologies for any confusion, I realize I forgot to include instructions on how to reproduce the issue. However, I want to clarify that this is not the source of the bug; it's related to other changes. Thank you for your understanding!

src/gridstack.ts Outdated
Comment on lines 2254 to 2255
delete node.grid._isTemp;
}
delete node.grid._isTemp;
Copy link
Contributor Author

@mustafamilyas mustafamilyas May 2, 2024

Choose a reason for hiding this comment

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

To reproduce the issue:

  1. Enable dragging a widget from outside onto the grid.
  2. Ensure the grid is crowded, leaving very little space (less than the size of the widget).
  3. Make sure the grid has defined rows, preventing movement.
  4. Drag the widget into that small space.

This will cause the addition of the widget to fail and become unresponsive. If you need further assistance, feel free to reach out. Thank you!

Copy link
Member

Choose a reason for hiding this comment

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

so this doesn't fix dropping into a full grid ? what does it fix then ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These changes should resolve the issue. The step provided is intended to demonstrate how to reproduce the issue before implementing these changes. I apologize if the explanation is unclear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The issue arises because 'node.grid' is populated only when the widget is added (line 2253). Therefore, if the widget fails to be added, an error occurs because the system attempts to delete 'node.grid._isTemp', which does not exist.

I'll aim to create a reproduction of the issue sometime next week, if that works for you.

Copy link
Member

Choose a reason for hiding this comment

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

if that's the case delete node.grid?._isTemp; woudl have suffice. I'll need to debug this to see the implication of move it out...

Copy link
Member

Choose a reason for hiding this comment

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

| The issue arises because 'node.grid' is populated only when the widget is added (line 2253)

no it could come from another grid as well... anyway the optional null check is safe and right thing to do, but I may need to exit sooner and not do some work, but for now that fixes the js error. thank you for the demo...

@sfragis
Copy link

sfragis commented May 9, 2024

Hi @mustafamilyas and @adumesny, does this PR also fix issue #2667 by any chance?

@adumesny
Copy link
Member

@sfragis nothing to do with it.

@mustafamilyas
Copy link
Contributor Author

@adumesny, apologies for the delay. I've made the adjustments as per your suggestion and tested them on my end. It seems to have resolved the issue at least on my side.

Below, you'll find a JSFiddle and a video demonstrating how to reproduce the error before the changes were made. Let me know if you need further assistance. Thank you!

https://jsfiddle.net/redmaze/jqw25fed/7/
https://www.loom.com/share/c89f4254d3e347d4adcc934d6bd71d74?sid=bc050e16-02a4-4170-aa60-c8b70d9936b1

@adumesny adumesny merged commit 9b6c68f into gridstack:master May 16, 2024
@adumesny
Copy link
Member

that demo is weird. items are places 1x1 first, then 2x1 (to match actual dragged size, what it should be) even if you don't resize the dropped item.

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

Successfully merging this pull request may close these issues.

3 participants