Skip to content

Commit

Permalink
Merge pull request #2907 from woocommerce/PCP-3959-do-not-trigger-bro…
Browse files Browse the repository at this point in the history
…wser-warning-when-using-save-and-exit

Disable the browser warning on page reload (3959)
  • Loading branch information
stracker-phil authored Dec 11, 2024
2 parents 0651871 + c99793a commit 3469ea7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,12 @@ import { OnboardingHooks } from '../../../data';

import { getSteps, getCurrentStep } from './availableSteps';
import Navigation from './Components/Navigation';
import { useEffect } from '@wordpress/element';

const Onboarding = () => {
const { step, setStep, flags } = OnboardingHooks.useSteps();
const Steps = getSteps( flags );
const currentStep = getCurrentStep( step, Steps );

// Disable the "Changes you made might not be saved" browser warning.
useEffect( () => {
const suppressBeforeUnload = ( event ) => {
event.stopImmediatePropagation();
return undefined;
};

window.addEventListener( 'beforeunload', suppressBeforeUnload );

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

const handleNext = () => setStep( currentStep.nextStep );
const handlePrev = () => setStep( currentStep.prevStep );
const handleExit = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMemo } from '@wordpress/element';
import { useEffect, useMemo } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import classNames from 'classnames';

Expand All @@ -11,6 +11,20 @@ import SettingsScreen from './SettingsScreen';
const Settings = () => {
const onboardingProgress = OnboardingHooks.useSteps();

// Disable the "Changes you made might not be saved" browser warning.
useEffect( () => {
const suppressBeforeUnload = ( event ) => {
event.stopImmediatePropagation();
return undefined;
};

window.addEventListener( 'beforeunload', suppressBeforeUnload );

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

const wrapperClass = classNames( 'ppcp-r-app', {
loading: ! onboardingProgress.isReady,
} );
Expand Down

0 comments on commit 3469ea7

Please sign in to comment.