Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/devextreme/js/__internal/ui/themes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ function readThemeMarker(): string | null {
let result: string;

try {
if (!window?.getComputedStyle) {
return null;
}
result = window.getComputedStyle(element.get(0)).fontFamily;
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

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

The fix only checks if window.getComputedStyle exists, but the tests expect the function to handle cases where getComputedStyle throws an error when called. The current implementation will still throw an error if getComputedStyle exists but throws when invoked. To properly handle this scenario, wrap the window.getComputedStyle call in a try-catch block within the existing try-finally structure.

Suggested change
result = window.getComputedStyle(element.get(0)).fontFamily;
let computedStyle;
try {
computedStyle = window.getComputedStyle(element.get(0));
} catch (e) {
return null;
}
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
result = computedStyle && computedStyle.fontFamily;

Copilot uses AI. Check for mistakes.
if (!result) {
return null;
Expand Down
36 changes: 36 additions & 0 deletions packages/devextreme/testing/tests/DevExpress.ui/themes.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -825,3 +825,39 @@ QUnit.module('initialized method', (hooks) => {
});
});
});

QUnit.module('readThemeMarker error handling', () => {
test('readThemeMarker returns null when getComputedStyle throws an error', function(assert) {
const done = assert.async();
const originalGetComputedStyle = window.getComputedStyle;
window.getComputedStyle = undefined;

try {
themes.resetTheme();
const value = themes.current();
assert.strictEqual(value, null, 'current() returns null on getComputedStyle being undefined');
} finally {
window.getComputedStyle = originalGetComputedStyle;
done();
}
});

test('waitForThemeLoad resolves even if getComputedStyle continuously throws', function(assert) {
const done = assert.async();
const originalGetComputedStyle = window.getComputedStyle;
window.getComputedStyle = undefined;

const TEST_TIMEOUT = 30;
themes.resetTheme();
themes.setDefaultTimeout(TEST_TIMEOUT);

themes.ready(() => {
assert.strictEqual(themes.current(), null, 'theme remains null after timeout');
window.getComputedStyle = originalGetComputedStyle;
themes.setDefaultTimeout(defaultTimeout);
done();
});

themes.waitForThemeLoad('some.nonexistent.theme');
});
});
Loading