Skip to content

Conversation

@ajivanyandev
Copy link
Contributor

No description provided.

Copilot AI review requested due to automatic review settings December 16, 2025 07:02
@ajivanyandev ajivanyandev self-assigned this Dec 16, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a Vitest compatibility issue where window.getComputedStyle errors are not handled gracefully in the readThemeMarker function. The fix adds a catch block to return null when getComputedStyle throws an error, preventing test failures in environments like Vitest where this method may not be fully implemented.

Key Changes:

  • Added error handling to readThemeMarker() function in themes.ts to catch and handle getComputedStyle errors
  • Added test coverage for the new error handling behavior

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
packages/devextreme/js/__internal/ui/themes.ts Added catch block to readThemeMarker() to gracefully handle getComputedStyle errors by returning null
packages/devextreme/testing/tests/DevExpress.ui/themes.tests.js Added two new tests to verify error handling when getComputedStyle throws errors

}
return result.substr(THEME_MARKER_PREFIX.length);
} catch (e) {
return null;
Copy link
Contributor

@VasilyStrelyaev VasilyStrelyaev Dec 16, 2025

Choose a reason for hiding this comment

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

I'm not sure I like this fix.

First, are we saying that it's normal that under vitest the window.getComputedStyles method is not mocked? Assuming we are in jsdom here, I can see it is in fact mocked:
https://github.com/jsdom/jsdom/blob/main/lib/jsdom/browser/Window.js#L908

and probably that's why this bug is not reproduced on macOS (and even on Parallels' Windows for ARM).

What's different on Windows x64?

And even if we think that it's too expensive to investigate this (do we?), okay, in this case we may want to support the case when there is no getComputedStyles in our environment. But is it a good way to do this with a blanket catch? Not checking for specific condition?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Let me investigate a little more, and come back

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Let me investigate a little more, and come back

Copilot AI review requested due to automatic review settings December 23, 2025 09:29
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants