fix(PersonTypeahead): sync searchTerm when initialName prop changes

After a person swap the parent navigates to a new URL and the server
returns swapped names. The component's searchTerm was only set once from
initialName at mount time ($state(initialName) captures the initial value
only). Adding a reactive $effect ensures the displayed name updates
whenever initialName changes — fixing the swap button showing stale names.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-03-30 14:53:45 +02:00
parent 3318b5f1c6
commit 56d79c919e

View File

@@ -30,8 +30,16 @@ let {
onfocused
}: Props = $props();
// searchTerm must be both prop-derived AND locally writable (user typing), so $state +
// $effect is the correct pattern here — writable $derived is read-only and won't work.
// eslint-disable-next-line svelte/prefer-writable-derived
let searchTerm = $state(initialName);
// Sync display text when the selected person changes externally (e.g. swap, navigation).
$effect(() => {
searchTerm = initialName;
});
$effect(() => {
const suggested = suggestedName;
if (suggested && !untrack(() => value)) {