Hi everyone,
I’m building a Shopify embedded app using @shopify/app-bridge-react
and I’m implementing the Contextual Save Bar (CSB) to handle unsaved changes in a form.
Here’s what I’m trying to achieve:
- When there are unsaved changes (
isChanged
is true), the CSB should appear. - Merchants must click “Save” or “Discard” before navigating away — this includes:
- In-app navigation (via links or buttons)
- Browser back button
- If a user tries to navigate away without acting on the CSB, the default Shopify “shake” animation should trigger on the Save Bar to draw their attention.
- I want to follow Shopify UX guidelines and not use a modal — this behavior should be handled via the CSB.
import { useContextualSaveBar } from '@shopify/app-bridge-react';
const { show, hide, saveAction, discardAction } = useContextualSaveBar();
useEffect(() => {
if (isChanged) {
show({ leaveConfirmationDisabled: true });
saveAction.setOptions({
disabled: false,
loading: isUpdateSettings,
label: 'Save Changes',
onAction: () => handleSubmit(),
});
discardAction.setOptions({
disabled: isUpdateSettings,
onAction: () => handleDiscard(),
});
} else {
hide({ leaveConfirmationDisabled: true });
}
}, [isChanged, isUpdateSettings]);
My Questions:
- How can I prevent any navigation when CSB is visible and unsaved changes exist?
- How do I trigger the default “shake” animation on the CSB when a user attempts to leave without saving or discarding?
- Is there a best-practice way to handle this in App Bridge React without manually attaching
beforeunload
ornavigation
intercepts?
I want to ensure the app behaves consistently with Shopify’s UI/UX expectations.
Thanks in advance for any help or code examples!