diff --git a/src/@types/global.d.ts b/src/@types/global.d.ts index 646fe6ea..90411e7b 100644 --- a/src/@types/global.d.ts +++ b/src/@types/global.d.ts @@ -14,9 +14,12 @@ See the License for the specific language governing permissions and limitations under the License. */ +type ReactNode = import("react").ReactNode; + interface Window { Olm: { init: () => Promise; }; mxSendRageshake: (text: string, withLogs?: boolean) => void; + matrixChat: ReactNode; } diff --git a/src/vector/app.js b/src/vector/app.js index 131e1ca4..dcdc4769 100644 --- a/src/vector/app.js +++ b/src/vector/app.js @@ -23,7 +23,6 @@ import React from 'react'; // access via the console global.React = React; -import ReactDOM from 'react-dom'; import * as sdk from 'matrix-react-sdk'; import PlatformPeg from 'matrix-react-sdk/src/PlatformPeg'; import * as VectorConferenceHandler from 'matrix-react-sdk/src/VectorConferenceHandler'; @@ -235,11 +234,7 @@ export async function loadApp() { ); const GenericErrorPage = sdk.getComponent("structures.GenericErrorPage"); - window.matrixChat = ReactDOM.render( - , - document.getElementById('matrixchat'), - ); - return; + return ; } const validBrowser = checkBrowserFeatures(); @@ -249,31 +244,29 @@ export async function loadApp() { const urlWithoutQuery = window.location.protocol + '//' + window.location.host + window.location.pathname; console.log("Vector starting at " + urlWithoutQuery); if (configError) { - window.matrixChat = ReactDOM.render(
+ return
Unable to load config file: please refresh the page to try again. -
, document.getElementById('matrixchat')); +
; } else if (validBrowser || acceptInvalidBrowser) { platform.startUpdater(); - // Don't bother loading the app until the config is verified - verifyServerConfig().then((newConfig) => { + try { + // Don't bother loading the app until the config is verified + const config = await verifyServerConfig(); const MatrixChat = sdk.getComponent('structures.MatrixChat'); - window.matrixChat = ReactDOM.render( - , - document.getElementById('matrixchat'), - ); - }).catch(err => { + return ; + } catch (err) { console.error(err); let errorMessage = err.translatedMessage @@ -282,23 +275,17 @@ export async function loadApp() { // Like the compatibility page, AWOOOOOGA at the user const GenericErrorPage = sdk.getComponent("structures.GenericErrorPage"); - window.matrixChat = ReactDOM.render( - , - document.getElementById('matrixchat'), - ); - }); + return ; + } } else { console.error("Browser is missing required features."); // take to a different landing page to AWOOOOOGA at the user const CompatibilityPage = sdk.getComponent("structures.CompatibilityPage"); - window.matrixChat = ReactDOM.render( - , - document.getElementById('matrixchat'), - ); + return ; } } @@ -384,7 +371,6 @@ async function verifyServerConfig() { } } - validatedConfig.isDefault = true; // Just in case we ever have to debug this diff --git a/src/vector/init.ts b/src/vector/init.ts index 2344a938..1933b788 100644 --- a/src/vector/init.ts +++ b/src/vector/init.ts @@ -20,6 +20,7 @@ limitations under the License. // @ts-ignore import olmWasmPath from "olm/olm.wasm"; import Olm from 'olm'; +import * as ReactDOM from "react-dom"; import * as languageHandler from "matrix-react-sdk/src/languageHandler"; import SettingsStore from "matrix-react-sdk/src/settings/SettingsStore"; @@ -142,5 +143,5 @@ export async function loadApp() { /* webpackChunkName: "riot-web-app" */ /* webpackPreload: true */ "./app"); - await module.loadApp(); + window.matrixChat = ReactDOM.render(await module.loadApp(), document.getElementById('matrixchat')); }