adopted-ember-addons / adopted-ember-addons/ember-sortable

this.sortableGroup.prepare() throws an error sometimes

Đang mở
#653 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
TypeScript
Star
299
Fork
159
Merge trung bình
4 ngày 6 giờ
Pull request đã merge (30 ngày)
4

Mô tả

**Error:**

> Cannot read properties of undefined (reading 'prepare')

Image

**Steps to reproduce?**

I unfortunately don't know how to reproduce this. I have 2 Sentry Replays where I see users get this error but they don't do anything special.

For our traffic it happens **very rarely** but still happened to 30 users 🤷‍♂️

Image

It looks like it's failing during some re-rendering & dragging but I tried 20x CPU slowdown and still no joi with reproduction.

I see some code is defensive when accessing `this.sortableGroup`:

https://github.com/adopted-ember-addons/ember-sortable/blob/5a2bba926daf36c0acaee0691c65e5b429ba1aaa/addon/src/modifiers/sortable-item.ts#L124-L130

but not in all places.

Maybe I could add a bit of defensiveness to `this.sortableGroup.prepare()` to prevent this error from being thrown?

----

Instead of simple optional chaining [I'd rather propose](https://github.com/adopted-ember-addons/ember-sortable/pull/655) this:

```diff
DRAG_ACTIONS.forEach((event) => window.addEventListener(event, dragThrottled));
END_ACTIONS.forEach((event) => window.addEventListener(event, drop));

+ if (!this.sortableGroup) return;

this.sortableGroup.prepare();
set(this, 'isDragging', true);
```

[I don't think anything below](https://github.com/adopted-ember-addons/ember-sortable/blob/5a2bba926daf36c0acaee0691c65e5b429ba1aaa/addon/src/modifiers/sortable-item.ts#L511-L514) `this.sortableGroup.prepare()` makes sense without `this.sortableGroup` being present 🤷‍♂️

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.