fix(#221): reset parent/color/delete state when navigating between tag edit pages
SvelteKit reuses the same +page.svelte instance on client-side navigation, so $state() initialisations only run on mount. Add an $effect keyed on data.tag.id to reset parentId, selectedColor and deleteConfirmName whenever the user switches to a different tag in the admin sidebar. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -21,6 +21,16 @@ function getInitialColor() {
|
||||
let parentId = $state(getInitialParentId());
|
||||
let selectedColor = $state(getInitialColor());
|
||||
|
||||
// SvelteKit reuses the same component instance when navigating between tags client-side.
|
||||
// $state() only initialises on mount, so we need an effect to reset local form state
|
||||
// whenever the server switches to a different tag.
|
||||
$effect(() => {
|
||||
void data.tag.id; // declare dependency
|
||||
parentId = data.tag.parentId ?? '';
|
||||
selectedColor = data.tag.color ?? '';
|
||||
deleteConfirmName = '';
|
||||
});
|
||||
|
||||
const colors = [
|
||||
'sage',
|
||||
'sienna',
|
||||
|
||||
Reference in New Issue
Block a user