Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Fix browser navigation not working between /home, /login, /register, etc #2383

Merged
merged 4 commits into from
Jan 3, 2019

Conversation

turt2live
Copy link
Member

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 element-hq/element-web#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.

@turt2live turt2live requested a review from a team December 21, 2018 00:49
@jryans jryans self-assigned this Dec 31, 2018
Copy link
Collaborator

@jryans jryans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this! I added a few questions to make sure I understand what's happening here.

src/components/structures/MatrixChat.js Show resolved Hide resolved
onLoginClick() {
onLoginClick(ev) {
ev.preventDefault();
ev.stopPropagation();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is preventDefault enough by itself, or do you really need stopPropagation also?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preventDefault is enough for our use case, although we manage the onClick handling and should prevent propagation as well to be safe.

src/components/structures/login/Login.js Show resolved Hide resolved
@turt2live turt2live assigned turt2live and unassigned jryans Jan 2, 2019
@turt2live
Copy link
Member Author

I'm not sure what I broke, but 0907775 breaks the build presumably due to a test failure (which test? who knows) and 9f8d5ba fixes it.

Also, I spent a bunch of time chasing a red herring because our build process has a failure in it despite the green status: element-hq/element-web#7985

@turt2live turt2live requested a review from jryans January 3, 2019 01:39
@turt2live turt2live assigned jryans and unassigned turt2live Jan 3, 2019
@turt2live turt2live changed the base branch from develop to experimental January 3, 2019 19:11
@turt2live turt2live changed the base branch from experimental to develop January 3, 2019 19:13
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 element-hq/element-web#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.
@turt2live turt2live changed the base branch from develop to experimental January 3, 2019 19:14
@jryans
Copy link
Collaborator

jryans commented Jan 3, 2019

I was curious about what actually failed in the earlier builds such as this one. I guess I missed when looking at the build before that bottom of the log says "This log is too long to be displayed. Please reduce the verbosity of your build or download the raw log."

At the end of that raw log, we see that npm run test was run in riot-web and 5 tests failed.

There are also various messages about Olm apparently not being installed throughout the log. This seems like a normal warning (since Olm is optional and not explicitly installed) which is only appearing because of the test failures, which triggered verbose browser logs to print.

I was able to replicate the test failures locally using your "take out setState" commit (b7c39d8) by running:

npm run build
npm run test

in riot-web.

The failing tests seem to be checking whether the MatrixChat state reaches LOGGED_IN after various actions, which is exactly what's being changed here, so it seems like they are indeed valid test failures.

@jryans jryans assigned turt2live and unassigned jryans Jan 3, 2019
@turt2live turt2live requested a review from jryans January 3, 2019 21:31
@turt2live turt2live assigned jryans and unassigned turt2live Jan 3, 2019
@turt2live
Copy link
Member Author

@jryans should good now, hopefully. Sorry for the forcepush - trying to avoid sticking revert commits into the PR.

@jryans
Copy link
Collaborator

jryans commented Jan 3, 2019

(I don't mind the force push personally... I think it's good to clean up the history where reasonable to do so.)

Copy link
Collaborator

@jryans jryans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks! 😁

@jryans jryans assigned turt2live and unassigned jryans Jan 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants