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 {