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

Patch: "Reloading the registration page should warn about data loss" #8377

Merged
merged 15 commits into from
Apr 29, 2022
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/components/structures/auth/Registration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,20 @@ export default class Registration extends React.Component<IProps, IState> {

componentDidMount() {
this.replaceClient(this.props.serverConfig);
//triggers a confirmation dialog for data loss before page unloads/refreshes
window.addEventListener("beforeunload", this.unloadCallback);
}

componentWillUnmount() {
window.removeEventListener("beforeunload", this.unloadCallback);
}

private unloadCallback = (event: BeforeUnloadEvent) => {
event.preventDefault();
Copy link
Member

Choose a reason for hiding this comment

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

This will always show the confirmation dialog

According to the specification, to show the confirmation dialog an event handler should call preventDefault() on the event.

(Empirically only in Firefox & Safari)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's now working as it should. I have tested it in the three browsers.

event.returnValue = "";
return "";
};

// TODO: [REACT-WARNING] Replace with appropriate lifecycle event
// eslint-disable-next-line
UNSAFE_componentWillReceiveProps(newProps) {
Expand Down