mirror of
https://github.com/element-hq/element-web
synced 2024-11-27 19:56:47 +03:00
Fix browser navigation not working between /home, /login, /register, etc
All of the anchors were pointed at `#` which, when clicked, would trigger a hash change in the browser. This change races the change made by the screen handling where the screen handling ends up losing. Because the hash is then tracked as empty rather than `#/login` (for example), the state machine considers future changes as no-ops and doesn't do anything with them. By using `preventDefault` and `stopPropagation` on the anchor click events, we prevent the browser from automatically going to an empty hash, which then means the screen handling isn't racing the browser, and the hash change state machine doesn't no-op. After applying that fix, going between pages worked great unless you were going from /login to /home. This is because the MatrixChat state machine was now out of sync (a `view` of `LOGIN` but a `page` of `HomePage` - an invalid state). All we have to do here is ensure the right view is used when navigating to the homepage. Fixes https://github.com/vector-im/riot-web/issues/4061 Note: the concerns in 4061 about logging out upon entering the view appear to have been solved. Navigating to the login page doesn't obliterate your session, at least in my testing.
This commit is contained in:
parent
ad47144355
commit
35c9dce241
5 changed files with 40 additions and 7 deletions
|
@ -91,11 +91,15 @@ class HomePage extends React.Component {
|
||||||
this._unmounted = true;
|
this._unmounted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
onLoginClick() {
|
onLoginClick(ev) {
|
||||||
|
ev.preventDefault();
|
||||||
|
ev.stopPropagation();
|
||||||
dis.dispatch({ action: 'start_login' });
|
dis.dispatch({ action: 'start_login' });
|
||||||
}
|
}
|
||||||
|
|
||||||
onRegisterClick() {
|
onRegisterClick(ev) {
|
||||||
|
ev.preventDefault();
|
||||||
|
ev.stopPropagation();
|
||||||
dis.dispatch({ action: 'start_registration' });
|
dis.dispatch({ action: 'start_registration' });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -927,6 +927,9 @@ export default React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
_viewHome: function() {
|
_viewHome: function() {
|
||||||
|
this.setStateForNewView({
|
||||||
|
view: VIEWS.LOGGED_IN,
|
||||||
|
});
|
||||||
this._setPage(PageTypes.HomePage);
|
this._setPage(PageTypes.HomePage);
|
||||||
this.notifyNewScreen('home');
|
this.notifyNewScreen('home');
|
||||||
},
|
},
|
||||||
|
|
|
@ -162,6 +162,18 @@ module.exports = React.createClass({
|
||||||
this.setState(newState);
|
this.setState(newState);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onLoginClick: function(ev) {
|
||||||
|
ev.preventDefault();
|
||||||
|
ev.stopPropagation();
|
||||||
|
this.props.onLoginClick();
|
||||||
|
},
|
||||||
|
|
||||||
|
onRegisterClick: function(ev) {
|
||||||
|
ev.preventDefault();
|
||||||
|
ev.stopPropagation();
|
||||||
|
this.props.onRegisterClick();
|
||||||
|
},
|
||||||
|
|
||||||
showErrorDialog: function(body, title) {
|
showErrorDialog: function(body, title) {
|
||||||
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
||||||
Modal.createTrackedDialog('Forgot Password Error', '', ErrorDialog, {
|
Modal.createTrackedDialog('Forgot Password Error', '', ErrorDialog, {
|
||||||
|
@ -253,10 +265,10 @@ module.exports = React.createClass({
|
||||||
</form>
|
</form>
|
||||||
{ serverConfigSection }
|
{ serverConfigSection }
|
||||||
{ errorText }
|
{ errorText }
|
||||||
<a className="mx_Login_create" onClick={this.props.onLoginClick} href="#">
|
<a className="mx_Login_create" onClick={this.onLoginClick} href="#">
|
||||||
{ _t('Return to login screen') }
|
{ _t('Return to login screen') }
|
||||||
</a>
|
</a>
|
||||||
<a className="mx_Login_create" onClick={this.props.onRegisterClick} href="#">
|
<a className="mx_Login_create" onClick={this.onRegisterClick} href="#">
|
||||||
{ _t('Create an account') }
|
{ _t('Create an account') }
|
||||||
</a>
|
</a>
|
||||||
<LanguageSelector />
|
<LanguageSelector />
|
||||||
|
|
|
@ -214,7 +214,9 @@ module.exports = React.createClass({
|
||||||
}).done();
|
}).done();
|
||||||
},
|
},
|
||||||
|
|
||||||
_onLoginAsGuestClick: function() {
|
_onLoginAsGuestClick: function(ev) {
|
||||||
|
ev.preventDefault();
|
||||||
|
|
||||||
const self = this;
|
const self = this;
|
||||||
self.setState({
|
self.setState({
|
||||||
busy: true,
|
busy: true,
|
||||||
|
@ -297,6 +299,12 @@ module.exports = React.createClass({
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onRegisterClick: function(ev) {
|
||||||
|
ev.preventDefault();
|
||||||
|
ev.stopPropagation();
|
||||||
|
this.props.onRegisterClick();
|
||||||
|
},
|
||||||
|
|
||||||
_tryWellKnownDiscovery: async function(serverName) {
|
_tryWellKnownDiscovery: async function(serverName) {
|
||||||
if (!serverName.trim()) {
|
if (!serverName.trim()) {
|
||||||
// Nothing to discover
|
// Nothing to discover
|
||||||
|
@ -567,7 +575,7 @@ module.exports = React.createClass({
|
||||||
{ errorTextSection }
|
{ errorTextSection }
|
||||||
{ this.componentForStep(this.state.currentFlow) }
|
{ this.componentForStep(this.state.currentFlow) }
|
||||||
{ serverConfig }
|
{ serverConfig }
|
||||||
<a className="mx_Login_create" onClick={this.props.onRegisterClick} href="#">
|
<a className="mx_Login_create" onClick={this.onRegisterClick} href="#">
|
||||||
{ _t('Create an account') }
|
{ _t('Create an account') }
|
||||||
</a>
|
</a>
|
||||||
{ loginAsGuestJsx }
|
{ loginAsGuestJsx }
|
||||||
|
|
|
@ -363,6 +363,12 @@ module.exports = React.createClass({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onLoginClick: function(ev) {
|
||||||
|
ev.preventDefault();
|
||||||
|
ev.stopPropagation();
|
||||||
|
this.props.onLoginClick();
|
||||||
|
},
|
||||||
|
|
||||||
_makeRegisterRequest: function(auth) {
|
_makeRegisterRequest: function(auth) {
|
||||||
// Only send the bind params if we're sending username / pw params
|
// Only send the bind params if we're sending username / pw params
|
||||||
// (Since we need to send no params at all to use the ones saved in the
|
// (Since we need to send no params at all to use the ones saved in the
|
||||||
|
@ -468,7 +474,7 @@ module.exports = React.createClass({
|
||||||
let signIn;
|
let signIn;
|
||||||
if (!this.state.doingUIAuth) {
|
if (!this.state.doingUIAuth) {
|
||||||
signIn = (
|
signIn = (
|
||||||
<a className="mx_Login_create" onClick={this.props.onLoginClick} href="#">
|
<a className="mx_Login_create" onClick={this.onLoginClick} href="#">
|
||||||
{ theme === 'status' ? _t('Sign in') : _t('I already have an account') }
|
{ theme === 'status' ? _t('Sign in') : _t('I already have an account') }
|
||||||
</a>
|
</a>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue