mirror of https://github.com/vector-im/riot-web
Fix a race in session loading code
it was possible for on_logging_in to get dispatched *after* on_logged_in, causing the app to wedge. Fix it by dispatching on_logging_in synchronously.pull/21833/head
parent
3e93930dcc
commit
f5f1fe6ae6
|
@ -309,7 +309,10 @@ async function _doSetLoggedIn(credentials, clearStorage) {
|
||||||
// because `teamPromise` may take some time to resolve, breaking the assumption that
|
// because `teamPromise` may take some time to resolve, breaking the assumption that
|
||||||
// `setLoggedIn` takes an "instant" to complete, and dispatch `on_logged_in` a few ms
|
// `setLoggedIn` takes an "instant" to complete, and dispatch `on_logged_in` a few ms
|
||||||
// later than MatrixChat might assume.
|
// later than MatrixChat might assume.
|
||||||
dis.dispatch({action: 'on_logging_in'});
|
//
|
||||||
|
// we fire it *synchronously* to make sure it fires before on_logged_in.
|
||||||
|
// (dis.dispatch uses `setTimeout`, which does not guarantee ordering.)
|
||||||
|
dis.dispatch({action: 'on_logging_in'}, true);
|
||||||
|
|
||||||
if (clearStorage) {
|
if (clearStorage) {
|
||||||
await _clearStorage();
|
await _clearStorage();
|
||||||
|
@ -344,6 +347,9 @@ async function _doSetLoggedIn(credentials, clearStorage) {
|
||||||
localStorage.setItem("mx_team_token", body.team_token);
|
localStorage.setItem("mx_team_token", body.team_token);
|
||||||
}
|
}
|
||||||
return body.team_token;
|
return body.team_token;
|
||||||
|
}, (err) => {
|
||||||
|
console.warn(`Failed to get team token on login: ${err}` );
|
||||||
|
return null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -354,9 +360,6 @@ async function _doSetLoggedIn(credentials, clearStorage) {
|
||||||
|
|
||||||
teamPromise.then((teamToken) => {
|
teamPromise.then((teamToken) => {
|
||||||
dis.dispatch({action: 'on_logged_in', teamToken: teamToken});
|
dis.dispatch({action: 'on_logged_in', teamToken: teamToken});
|
||||||
}, (err) => {
|
|
||||||
console.warn("Failed to get team token on login", err);
|
|
||||||
dis.dispatch({action: 'on_logged_in', teamToken: null});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
startMatrixClient();
|
startMatrixClient();
|
||||||
|
|
Loading…
Reference in New Issue