зеркало из https://github.com/mozilla/fxa.git
Bug(settings): Fix for 'stuck' sign in button p2
Because: - When signing into sync on Android, the signin button can become 'stuck' - Yesterday we uncovered a race condition that seemed to help, but didn't totally fix the problem. - The event handler in fxaCanLinkAccount was too general and could pick up events that were not intended for it. This Commit: - Uses `this.addEventListener(FirefoxCommand.CanLinkAccount` instead of `window.addEventListener('WebChannelMessageToContent'...` - Doing so ensures that only responses for the CanLinkAccount command are handled. Note, we should avoid using `window.addEventListener('WebChannelMessageToContent'`
This commit is contained in:
Родитель
3dcf99ed7d
Коммит
d8067acd52
|
@ -350,18 +350,12 @@ export class Firefox extends EventTarget {
|
|||
options: FxACanLinkAccount
|
||||
): Promise<FxACanLinkAccountResponse> {
|
||||
return new Promise((resolve) => {
|
||||
const eventHandler = (event: Event) => {
|
||||
const firefoxEvent = event as FirefoxEvent;
|
||||
const detail =
|
||||
typeof firefoxEvent.detail === 'string'
|
||||
? (JSON.parse(firefoxEvent.detail) as FirefoxMessageDetail)
|
||||
: firefoxEvent.detail;
|
||||
|
||||
resolve(detail.message?.data as FxACanLinkAccountResponse);
|
||||
const eventHandler = (firefoxEvent: any) => {
|
||||
this.removeEventListener(FirefoxCommand.CanLinkAccount, eventHandler);
|
||||
resolve(firefoxEvent.detail || { ok: false });
|
||||
};
|
||||
window.addEventListener('WebChannelMessageToContent', eventHandler);
|
||||
// requestAnimationFrame ensures the event listener is added first
|
||||
// otherwise, there is a race condition
|
||||
|
||||
this.addEventListener(FirefoxCommand.CanLinkAccount, eventHandler);
|
||||
requestAnimationFrame(() => {
|
||||
this.send(FirefoxCommand.CanLinkAccount, options);
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче