From 157a136dd6252aaeb105173c11629e4e196d5ec0 Mon Sep 17 00:00:00 2001 From: Alexia Christelle Date: Tue, 15 Jul 2025 10:55:32 +0200 Subject: [PATCH] Fixed the navigation without first chekcing for unsaved changes --- .../components/ResourceItem/ResourceItem.tsx | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/polaris-react/src/components/ResourceItem/ResourceItem.tsx b/polaris-react/src/components/ResourceItem/ResourceItem.tsx index 1253d6fabe5..1d3d42f8d6d 100644 --- a/polaris-react/src/components/ResourceItem/ResourceItem.tsx +++ b/polaris-react/src/components/ResourceItem/ResourceItem.tsx @@ -455,10 +455,26 @@ class BaseResourceItem extends Component { } if (url && anchor) { - anchor.click(); + // PREVENT default navigation + event.preventDefault(); + // Check savebar BEFORE navigating + this.handleNavigationWithSaveBarCheck(anchor); } }; + private async handleNavigationWithSaveBarCheck(anchor: HTMLAnchorElement) { + try { + // Check if shopify saveBar is available and has active unsaved changes + if (typeof window !== 'undefined' && (window as any).shopify?.saveBar) { + await (window as any).shopify.saveBar.leaveConfirmation(); + } + // Only navigate if confirmation succeeds + window.location.href = anchor.href; + } catch (error) { + // User cancelled - don't navigate + } + } + // This fires onClick when there is a URL on the item private handleKeyUp = (event: React.KeyboardEvent) => { const {