From 20705cc3b27f3f81d0fea1359a65dcd14b0f9f5b Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Mon, 1 Dec 2025 05:02:56 -0800 Subject: [PATCH] SegmentedControl: only fire onValueChange on actual changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prevents onValueChange from firing during initialization, which caused pushState errors before router was ready. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../ui/segmented-control/SegmentedControl.svelte | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lib/components/ui/segmented-control/SegmentedControl.svelte b/src/lib/components/ui/segmented-control/SegmentedControl.svelte index 7cf865ea..92962c93 100644 --- a/src/lib/components/ui/segmented-control/SegmentedControl.svelte +++ b/src/lib/components/ui/segmented-control/SegmentedControl.svelte @@ -37,9 +37,16 @@ // Provide variant to child segments via context setContext('segmented-control-variant', variant) + // Track previous value to only fire callback on actual changes (not initialization) + let previousValue = $state(undefined) + $effect(() => { if (onValueChange && value !== undefined) { - onValueChange(value) + // Only call onValueChange if value actually changed (not on initialization) + if (previousValue !== undefined && value !== previousValue) { + onValueChange(value) + } + previousValue = value } })