Skip to content

Commit

Permalink
TASK: Add beforeunload handler during publish/discard
Browse files Browse the repository at this point in the history
  • Loading branch information
grebaldi committed Mar 29, 2024
1 parent 8b81c31 commit 25e88e0
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/neos-ui-sagas/src/Publish/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import {TypeOfChange} from '@neos-project/neos-ui-redux-store/src/CR/Workspaces'
import backend from '@neos-project/neos-ui-backend-connector';
import {getGuestFrameDocument} from '@neos-project/neos-ui-guest-frame/src/dom';

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

export function * watchPublishing({routes}) {
const {endpoints} = backend.get();
const ENDPOINT_BY_MODE_AND_SCOPE = {
Expand Down Expand Up @@ -50,6 +56,7 @@ export function * watchPublishing({routes}) {
let affectedNodes = [];
do {
try {
window.addEventListener('beforeunload', handleWindowBeforeUnload);
const result = yield call(endpoint, ancestorId, workspaceName);

if ('success' in result) {
Expand All @@ -66,6 +73,8 @@ export function * watchPublishing({routes}) {
}
} catch (error) {
yield put(actions.CR.Publishing.fail(error));
} finally {
window.removeEventListener('beforeunload', handleWindowBeforeUnload);
}
} while (yield * waitForRetry());

Expand Down

0 comments on commit 25e88e0

Please sign in to comment.