fix(app): post-route lädt reaktiv via $effect statt onMount

bei navigation zwischen slugs innerhalb der gleichen [...slug]-route
bleibt die komponente montiert — onMount feuert dann nicht mehr, und
der neue post lud erst nach manuellem reload. $effect auf dtag löst
das und rendert die neue view sofort.

race-condition-guard: currentDtag wird pro effect-lauf festgefroren;
stale responses werden verworfen.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jörg Lohrer 2026-04-21 13:17:41 +02:00
parent bf7b52ab9b
commit 0fca9cbfa2
1 changed files with 21 additions and 14 deletions

View File

@ -1,5 +1,4 @@
<script lang="ts"> <script lang="ts">
import { onMount } from 'svelte';
import type { NostrEvent } from '$lib/nostr/loaders'; import type { NostrEvent } from '$lib/nostr/loaders';
import { loadPost } from '$lib/nostr/loaders'; import { loadPost } from '$lib/nostr/loaders';
import { AUTHOR_PUBKEY_HEX } from '$lib/nostr/config'; import { AUTHOR_PUBKEY_HEX } from '$lib/nostr/config';
@ -22,19 +21,27 @@
}) })
); );
onMount(async () => { $effect(() => {
try { const currentDtag = dtag;
const p = await loadPost(dtag); post = null;
loading = false; loading = true;
if (!p) { error = null;
error = `Post "${dtag}" nicht gefunden.`; loadPost(currentDtag)
} else { .then((p) => {
post = p; if (currentDtag !== dtag) return;
} if (!p) {
} catch (e) { error = `Post "${currentDtag}" nicht gefunden.`;
loading = false; } else {
error = e instanceof Error ? e.message : 'Unbekannter Fehler'; post = p;
} }
})
.catch((e) => {
if (currentDtag !== dtag) return;
error = e instanceof Error ? e.message : 'Unbekannter Fehler';
})
.finally(() => {
if (currentDtag === dtag) loading = false;
});
}); });
</script> </script>