SegmentedControl: only fire onValueChange on actual changes

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 <noreply@anthropic.com>
This commit is contained in:
Justin Edmund 2025-12-01 05:02:56 -08:00
parent 83b18645c8
commit 20705cc3b2

View file

@ -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<string | undefined>(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
}
})