From 0040181489feda0e5d70becdea8585ac5a344d99 Mon Sep 17 00:00:00 2001 From: Dominik Henneke Date: Thu, 19 Oct 2023 03:13:30 +0200 Subject: [PATCH] Correctly fill window.matrixChat even when a Wrapper module is active (#26395) Signed-off-by: Dominik Henneke --- src/vector/app.tsx | 3 ++- src/vector/init.tsx | 6 +++++- test/app-tests/server-config-test.ts | 6 +++--- test/app-tests/wrapper-test.tsx | 7 ++++++- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/vector/app.tsx b/src/vector/app.tsx index 11534d4d64..68dd8229a2 100644 --- a/src/vector/app.tsx +++ b/src/vector/app.tsx @@ -65,7 +65,7 @@ function onTokenLoginCompleted(): void { window.history.replaceState(null, "", url.href); } -export async function loadApp(fragParams: {}): Promise { +export async function loadApp(fragParams: {}, matrixChatRef: React.Ref): Promise { initRouting(); const platform = PlatformPeg.get(); @@ -117,6 +117,7 @@ export async function loadApp(fragParams: {}): Promise { return ( { /* webpackPreload: true */ "./app" ); - window.matrixChat = ReactDOM.render(await module.loadApp(fragParams), document.getElementById("matrixchat")); + function setWindowMatrixChat(matrixChat: MatrixChat): void { + window.matrixChat = matrixChat; + } + ReactDOM.render(await module.loadApp(fragParams, setWindowMatrixChat), document.getElementById("matrixchat")); } export async function showError(title: string, messages?: string[]): Promise { diff --git a/test/app-tests/server-config-test.ts b/test/app-tests/server-config-test.ts index b469daf28d..e18b766db3 100644 --- a/test/app-tests/server-config-test.ts +++ b/test/app-tests/server-config-test.ts @@ -47,7 +47,7 @@ describe("Loading server config", function () { }, }, }); - await loadApp({}); + await loadApp({}, null); expect((SdkConfig.get("validated_server_config") || {}).hsUrl).toBe("https://matrix-client.matrix.org"); }); @@ -55,7 +55,7 @@ describe("Loading server config", function () { SdkConfig.put({ default_server_name: "matrix.org", }); - await loadApp({}); + await loadApp({}, null); expect((SdkConfig.get("validated_server_config") || {}).hsUrl).toBe("https://matrix-client.matrix.org"); }); @@ -72,7 +72,7 @@ describe("Loading server config", function () { }, }, }); - await loadApp({}); + await loadApp({}, null); expect((SdkConfig.get("validated_server_config") || {}).hsUrl).toBe("https://matrix-client.matrix.org"); }, ); diff --git a/test/app-tests/wrapper-test.tsx b/test/app-tests/wrapper-test.tsx index 6f72dbb606..0ba1d3f080 100644 --- a/test/app-tests/wrapper-test.tsx +++ b/test/app-tests/wrapper-test.tsx @@ -22,6 +22,7 @@ import fetchMock from "fetch-mock-jest"; import { render, RenderResult, screen } from "@testing-library/react"; import { ModuleRunner } from "matrix-react-sdk/src/modules/ModuleRunner"; import { WrapperLifecycle, WrapperOpts } from "@matrix-org/react-sdk-module-api/lib/lifecycles/WrapperLifecycle"; +import MatrixChat from "matrix-react-sdk/src/components/structures/MatrixChat"; import WebPlatform from "../../src/vector/platform/WebPlatform"; import { loadApp } from "../../src/vector/app"; @@ -68,7 +69,8 @@ describe("Wrapper", () => { } }); - const matrixChatResult: RenderResult = render(await loadApp({})); + const ref = React.createRef(); + const matrixChatResult: RenderResult = render(await loadApp({}, ref)); // at this point, we're trying to do a guest registration; // we expect a spinner @@ -83,5 +85,8 @@ describe("Wrapper", () => { expect(header.nextSibling).toBe(matrixChat); expect(matrixChat.nextSibling).toBe(footer); + + // Should still hold a reference to the MatrixChat component + expect(ref.current).toBeInstanceOf(MatrixChat); }); });