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 all 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
13 changes: 13 additions & 0 deletions src/components/structures/auth/Registration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,21 @@ 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) => {
if (this.state.doingUIAuth) {
event.preventDefault();
event.returnValue = "";
return "";
}
};
// TODO: [REACT-WARNING] Replace with appropriate lifecycle event
// eslint-disable-next-line
UNSAFE_componentWillReceiveProps(newProps) {
Expand Down