refactor(stammbaum): initialise selectedId directly from focusId, drop $effect
The focus deep-link is a one-time load param — $derived + $effect caused a deferred write that left the node unselected on first paint. Initialising $state inline reads the URL once at component mount with no reactive cycle. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -14,15 +14,12 @@ interface Props {
|
|||||||
|
|
||||||
let { data }: Props = $props();
|
let { data }: Props = $props();
|
||||||
|
|
||||||
const focusId = $derived(page.url.searchParams.get('focus'));
|
|
||||||
const canWrite = $derived<boolean>(page.data.canWrite ?? false);
|
const canWrite = $derived<boolean>(page.data.canWrite ?? false);
|
||||||
|
|
||||||
let selectedId = $state<string | null>(null);
|
const focusId = page.url.searchParams.get('focus');
|
||||||
$effect(() => {
|
let selectedId = $state<string | null>(
|
||||||
if (focusId && data.nodes.some((n) => n.id === focusId)) {
|
focusId && data.nodes.some((n) => n.id === focusId) ? focusId : null
|
||||||
selectedId = focusId;
|
);
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const selectedNode = $derived(data.nodes.find((n) => n.id === selectedId) ?? null);
|
const selectedNode = $derived(data.nodes.find((n) => n.id === selectedId) ?? null);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user