fix: sync reactive state with data prop using \$effect
Replaces bare \$state(data.x) initialisers (which only capture the initial value) with \$state + \$effect pairs so that state stays in sync whenever page data is invalidated or the URL changes. Affects all list pages (searchValue) and all edit/detail pages (form fields). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -28,6 +28,20 @@
|
||||
);
|
||||
let imageId = $state<string | null>(data.article.image ?? null);
|
||||
let authorId = $state(data.article.author?.id ?? "");
|
||||
$effect(() => {
|
||||
title = data.article.title;
|
||||
slug = data.article.slug;
|
||||
excerpt = data.article.excerpt ?? "";
|
||||
content = data.article.content ?? "";
|
||||
category = data.article.category ?? "";
|
||||
tags = data.article.tags ?? [];
|
||||
featured = data.article.featured ?? false;
|
||||
publishDate = data.article.publish_date
|
||||
? new Date(data.article.publish_date).toISOString().slice(0, 16)
|
||||
: "";
|
||||
imageId = data.article.image ?? null;
|
||||
authorId = data.article.author?.id ?? "";
|
||||
});
|
||||
let selectedAuthor = $derived(data.authors.find((a) => a.id === authorId) ?? null);
|
||||
let saving = $state(false);
|
||||
let editorTab = $state<"write" | "preview">("write");
|
||||
|
||||
Reference in New Issue
Block a user