Skip to content

Commit

Permalink
TASK: Add beforeunload handler during rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
grebaldi committed Apr 11, 2024
1 parent b66393c commit bf53841
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/neos-ui-sagas/src/Sync/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ type Endpoints = ReturnType<typeof Endpoints>;

import {makeReloadNodes} from '../CR/NodeOperations/reloadNodes';

const handleWindowBeforeUnload = (event: BeforeUnloadEvent) => {
event.preventDefault();
event.returnValue = true;
return true;
};

type SyncWorkspaceResult =
| { success: true }
| { conflicts: Conflict[] }
Expand Down Expand Up @@ -68,6 +74,7 @@ const makeSyncPersonalWorkspace = (deps: {
const dimensionSpacePoint: null|DimensionCombination = yield select(selectors.CR.ContentDimensions.active);

try {
window.addEventListener('beforeunload', handleWindowBeforeUnload);
const result: SyncWorkspaceResult = yield call(syncWorkspace, personalWorkspaceName, force, dimensionSpacePoint);
if ('success' in result) {
yield * refreshAfterSyncing();
Expand All @@ -79,6 +86,8 @@ const makeSyncPersonalWorkspace = (deps: {
}
} catch (error) {
yield put(actions.CR.Syncing.fail(error as AnyError));
} finally {
window.removeEventListener('beforeunload', handleWindowBeforeUnload);
}
}

Expand Down

0 comments on commit bf53841

Please sign in to comment.