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

Commit b4da870

Browse files
authored
Patch: "Reloading the registration page should warn about data loss" (#8377)
1 parent 6cb29f2 commit b4da870

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/components/structures/auth/Registration.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,21 @@ export default class Registration extends React.Component<IProps, IState> {
139139

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

146+
componentWillUnmount() {
147+
window.removeEventListener("beforeunload", this.unloadCallback);
148+
}
149+
150+
private unloadCallback = (event: BeforeUnloadEvent) => {
151+
if (this.state.doingUIAuth) {
152+
event.preventDefault();
153+
event.returnValue = "";
154+
return "";
155+
}
156+
};
144157
// TODO: [REACT-WARNING] Replace with appropriate lifecycle event
145158
// eslint-disable-next-line
146159
UNSAFE_componentWillReceiveProps(newProps) {

0 commit comments

Comments
 (0)