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();
|
||||
|
||||
const focusId = $derived(page.url.searchParams.get('focus'));
|
||||
const canWrite = $derived<boolean>(page.data.canWrite ?? false);
|
||||
|
||||
let selectedId = $state<string | null>(null);
|
||||
$effect(() => {
|
||||
if (focusId && data.nodes.some((n) => n.id === focusId)) {
|
||||
selectedId = focusId;
|
||||
}
|
||||
});
|
||||
const focusId = page.url.searchParams.get('focus');
|
||||
let selectedId = $state<string | null>(
|
||||
focusId && data.nodes.some((n) => n.id === focusId) ? focusId : null
|
||||
);
|
||||
|
||||
const selectedNode = $derived(data.nodes.find((n) => n.id === selectedId) ?? null);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user