Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prompt for page refresh, tab close #1987

Merged
merged 4 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 3 additions & 4 deletions packages/react-sdk/src/primitives/HmsRoomProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,10 @@ export const HMSRoomProvider = <T extends HMSGenericTypes = { sessionStore: Reco

useEffect(() => {
if (isBrowser && leaveOnUnload) {
const beforeUnloadCallback = () => providerProps.actions.leave();
window.addEventListener('beforeunload', beforeUnloadCallback);

const unloadCallback = () => providerProps.actions.leave();
window.addEventListener('unload', unloadCallback);
return () => {
window.removeEventListener('beforeunload', beforeUnloadCallback);
window.removeEventListener('unload', unloadCallback);
raviteja83 marked this conversation as resolved.
Show resolved Hide resolved
};
}

Expand Down
13 changes: 13 additions & 0 deletions packages/roomkit-react/src/Prebuilt/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,19 @@ export const HMSPrebuilt = React.forwardRef<HMSPrebuiltRefType, HMSPrebuiltProps
[],
);

// Prompt for page refresh/tab close
useEffect(() => {
const confirmLeave = (e: BeforeUnloadEvent) => {
raviteja83 marked this conversation as resolved.
Show resolved Hide resolved
e.returnValue = 'Are you sure you want to leave?';
};

window.addEventListener('beforeunload', confirmLeave);

return () => {
window.removeEventListener('beforeunload', confirmLeave);
};
}, []);

const endpointsObj = endpoints as
| {
init: string;
Expand Down
Loading