From 2b61c052b446af8610652b899e070661b2af56c5 Mon Sep 17 00:00:00 2001 From: Diego Imbert Date: Tue, 9 Jun 2026 14:43:26 +0200 Subject: [PATCH] fix(drafts): suppress 'You have unsaved changes' banner when deployed baseline is null MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A brand-new variable/resource/trigger (no deployed row yet) has `getDeployed() == null`, but the caller's `show` prop is computed off `current != deployed` which is trivially true while the user types. Result: the banner appeared with 'Show diff' (no-op — the drawer early-returns on null deployed) and a 'Discard' that's semantically backwards (there's nothing to revert to). Gate `show` internally on `getDeployed() != null`. The check sits in the banner rather than each caller because every caller would otherwise need the same boilerplate guard. --- frontend/src/lib/components/LocalDraftBanner.svelte | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/frontend/src/lib/components/LocalDraftBanner.svelte b/frontend/src/lib/components/LocalDraftBanner.svelte index 2fb2de4c11..bc21e97ad5 100644 --- a/frontend/src/lib/components/LocalDraftBanner.svelte +++ b/frontend/src/lib/components/LocalDraftBanner.svelte @@ -31,6 +31,15 @@ title = 'Deployed <> Local changes' }: Props = $props() + // Suppress the banner when there's no deployed baseline to diff + // against — a brand-new entity (variable/resource/trigger with no + // deployed row yet) has deployed == null, so "Show diff" would do + // nothing (the drawer early-returns) and "Discard changes" is + // semantically backwards (there's nothing to revert to). The + // callers' own `show` is computed off `current != deployed` which + // is trivially true in that case, so the gate has to live here. + let visible = $derived(show && getDeployed() != null) + let diffDrawer: DiffDrawer | undefined = $state() function showDiff() { @@ -66,7 +75,7 @@ -{#if show} +{#if visible}