Skip to content
This repository was archived by the owner on Oct 22, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions src/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ export function getOrderedThemes(): ITheme[] {

function clearCustomTheme(): void {
// remove all css variables, we assume these are there because of the custom theme
const inlineStyleProps = Object.values(document.body.style);
for (const prop of inlineStyleProps) {
for (let i = 0; i < document.body.style.length; i++) {
const prop = document.body.style[i];
Copy link
Member

@richvdh richvdh Sep 30, 2024

Choose a reason for hiding this comment

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

The JSDom CSSDeclaration stuff doesn't behave exactly the same as it does in browsers. Namely the object

"the object" here being document.body.style ? Which is supposed to be a CSSStyleDeclaration but maybe isn't?

has a bunch of extra fields which don't match the types we come to expect from the signature, so changing the way we iterate it fixes that.

Ok, but:

  • why was it intermittent?
  • Again, a comment here explaining that we're working around jsdom weirdness would be good. The first thing I want to do when I see this code is refactor it to for (const prop of document.body.style) { ... }, which for any normal array-like-object would be identical.

Copy link
Member Author

Choose a reason for hiding this comment

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

why was it intermittent?

Race condition between the test & ThemeWatcher

Copy link
Member Author

Choose a reason for hiding this comment

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

This part was inherently just defensive against JSDom but should be superfluous given the stubbing out of ThemeWatcher

if (prop.startsWith("--")) {
document.body.style.removeProperty(prop);
}
Expand Down
1 change: 1 addition & 0 deletions test/components/structures/MatrixChat-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import { UIFeature } from "../../../src/settings/UIFeature";
jest.mock("matrix-js-sdk/src/oidc/authorize", () => ({
completeAuthorizationCodeGrant: jest.fn(),
}));
jest.mock("../../../src/settings/watchers/ThemeWatcher");
Copy link
Member

Choose a reason for hiding this comment

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

There was then another flake where we're rendering MatrixChat without the bits of element-web's index.html which set up styles which caused a race condition with the ThemeWatcher firing off other bits of theming code which were unhappy to be missing the theme bits in index.html

maybe add a comment here to explain that, and say we're disabling ThemeWatcher?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done


/** The matrix versions our mock server claims to support */
const SERVER_SUPPORTED_MATRIX_VERSIONS = ["v1.1", "v1.5", "v1.6", "v1.8", "v1.9"];
Expand Down
Loading