From a853751f5f191abde2b13c9b1c7b07ddaaf2814f Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 25 Oct 2021 10:40:42 +0100 Subject: [PATCH 1/2] Clean up dialogTermsInteractionCallback to explode more cleanly --- src/Terms.ts | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/Terms.ts b/src/Terms.ts index 86d006c832b..218ad8ab6fd 100644 --- a/src/Terms.ts +++ b/src/Terms.ts @@ -181,7 +181,7 @@ export async function startTermsFlow( return Promise.all(agreePromises); } -export function dialogTermsInteractionCallback( +export async function dialogTermsInteractionCallback( policiesAndServicePairs: { service: Service; policies: { [policy: string]: Policy }; @@ -189,21 +189,18 @@ export function dialogTermsInteractionCallback( agreedUrls: string[], extraClassNames?: string, ): Promise { - return new Promise((resolve, reject) => { - logger.log("Terms that need agreement", policiesAndServicePairs); - // FIXME: Using an import will result in test failures - const TermsDialog = sdk.getComponent("views.dialogs.TermsDialog"); - - Modal.createTrackedDialog('Terms of Service', '', TermsDialog, { - policiesAndServicePairs, - agreedUrls, - onFinished: (done, agreedUrls) => { - if (!done) { - reject(new TermsNotSignedError()); - return; - } - resolve(agreedUrls); - }, - }, classNames("mx_TermsDialog", extraClassNames)); - }); + logger.log("Terms that need agreement", policiesAndServicePairs); + // FIXME: Using an import will result in test failures + const TermsDialog = sdk.getComponent("views.dialogs.TermsDialog"); + + const { finished } = Modal.createTrackedDialog<[boolean, string[]]>('Terms of Service', '', TermsDialog, { + policiesAndServicePairs, + agreedUrls, + }, classNames("mx_TermsDialog", extraClassNames)); + + const [done, _agreedUrls] = await finished; + if (!done) { + throw new TermsNotSignedError(); + } + return _agreedUrls; } From 2d0e8701f5d2051479783873b91e83d73a90e9ea Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 25 Oct 2021 10:40:59 +0100 Subject: [PATCH 2/2] Fix ModalManager reRender racing with itself --- src/Modal.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Modal.tsx b/src/Modal.tsx index 1e84078ddb9..a802e36d967 100644 --- a/src/Modal.tsx +++ b/src/Modal.tsx @@ -18,7 +18,7 @@ limitations under the License. import React from 'react'; import ReactDOM from 'react-dom'; import classNames from 'classnames'; -import { defer } from "matrix-js-sdk/src/utils"; +import { defer, sleep } from "matrix-js-sdk/src/utils"; import Analytics from './Analytics'; import dis from './dispatcher/dispatcher'; @@ -332,7 +332,10 @@ export class ModalManager { return this.priorityModal ? this.priorityModal : (this.modals[0] || this.staticModal); } - private reRender() { + private async reRender() { + // await next tick because sometimes ReactDOM can race with itself and cause the modal to wrongly stick around + await sleep(0); + if (this.modals.length === 0 && !this.priorityModal && !this.staticModal) { // If there is no modal to render, make all of Element available // to screen reader users again