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