Skip to content

Commit 2da455c

Browse files
Fix TypeError on accessing a component instance while unmounting (T1327953) (#33526)
1 parent b0e4888 commit 2da455c

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

packages/devextreme-react/src/core/__tests__/props-updating.test.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,38 @@ describe('cfg-component option control', () => {
10421042
expect((optionsManager as any).setValue).toHaveBeenCalledTimes(1);
10431043
});
10441044

1045+
it('does not crash when option change handler unmounts component (T1327953)', () => {
1046+
const optionsManager = new OptionsManagerModule.OptionsManager();
1047+
const config = {
1048+
name: '',
1049+
predefinedOptions: {},
1050+
initialOptions: {},
1051+
options: {
1052+
value: 1,
1053+
onValueChange: () => {
1054+
optionsManager.dispose();
1055+
},
1056+
},
1057+
templates: [],
1058+
configs: {},
1059+
configCollections: {},
1060+
};
1061+
1062+
optionsManager.setInstance({
1063+
skipOptionsRollBack: false,
1064+
option: jest.fn(),
1065+
resetOption: jest.fn(),
1066+
on: jest.fn(),
1067+
off: jest.fn(),
1068+
beginUpdate: jest.fn(),
1069+
endUpdate: jest.fn(),
1070+
}, config, ['value'], []);
1071+
1072+
expect(() => {
1073+
optionsManager.onOptionChanged({ name: 'value', value: 2, fullName: 'value' });
1074+
}).not.toThrow();
1075+
});
1076+
10451077
it('apply cfg-component option change if value really change', () => {
10461078
const TestContainer = (props: any) => {
10471079
const { value } = props;

packages/devextreme-react/src/core/options-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class OptionsManager {
160160
&& e.value instanceof Object
161161
&& shallowEquals(value as Record<string, unknown>, e.value as Record<string, unknown>);
162162

163-
if (valuesAreEqual || valuesAreEqualObjects || this.instance.skipOptionsRollBack) {
163+
if (valuesAreEqual || valuesAreEqualObjects || this.instance?.skipOptionsRollBack) {
164164
return;
165165
}
166166

0 commit comments

Comments
 (0)