Skip to content

Commit fb5f54f

Browse files
Draggable - Add safety guards for Angular SSR and disposal (DevExpress#33775)
1 parent 1679c7d commit fb5f54f

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

packages/devextreme-angular/src/server/render.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ export class DxServerModule {
2525
temp.innerHTML = renderToString(el);
2626

2727
const mainElement = temp.childNodes[0];
28+
if (!mainElement) {
29+
return;
30+
}
2831
const childString = mainElement.innerHTML;
2932

3033
for (let i = 0; i < mainElement.attributes.length; i++) {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import $ from '@js/core/renderer';
2+
import Sortable from '@js/ui/sortable';
3+
4+
describe('Draggable dispose safety', () => {
5+
beforeEach(() => {
6+
document.body.innerHTML = '';
7+
});
8+
9+
it('should not crash on _stopAnimator when _scrollAnimator is not initialized', () => {
10+
const $container = $('<div>').appendTo(document.body);
11+
const sortable = new Sortable($container, {});
12+
13+
(sortable as any)._scrollAnimator = undefined;
14+
15+
expect(() => {
16+
sortable.dispose();
17+
}).not.toThrow();
18+
});
19+
});

packages/devextreme/js/__internal/m_draggable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ class Draggable extends DOMComponent<Draggable, Properties> {
439439
}
440440

441441
_stopAnimator() {
442-
this._scrollAnimator.stop();
442+
this._scrollAnimator?.stop();
443443
}
444444

445445
_addWidgetPrefix(className?) {

0 commit comments

Comments
 (0)