fix: guard against double-publish and dropped relay params

Per review:
- handlePublish now also checks publish.isPending itself, not just
  the button's disabled state — a second click landing before React
  re-renders could otherwise fire mutateAsync twice.
- Publishing a draft now merges into the existing params instead of
  replacing them outright, so relay hints (or anything else already
  in params) survive the id being added.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BYiUtZMQeA5RHggQw73wto
This commit is contained in:
2026-09-06 17:56:26 +02:00
parent fc8c3d5ad4
commit 1e4051f15a
2 changed files with 5 additions and 2 deletions

View File

@@ -27,7 +27,10 @@ export function DraftNote({ onPublished }: { onPublished: (id: string) => void }
const trimmed = draft.trim();
const handlePublish = async () => {
if (!trimmed) return;
// Guarded here too, not just via the button's `disabled` — React hasn't
// necessarily re-rendered with publish.isPending yet when a second click
// lands in the same tick, and mutateAsync itself doesn't dedupe calls.
if (!trimmed || publish.isPending) return;
try {
const event = await publish.mutateAsync({ kind: 1, content: trimmed, tags: [] });
setDraft('');

View File

@@ -67,7 +67,7 @@ export default function NotesApp({ params, setTitle, setParams }: AppProps) {
}, [id, name, setTitle]);
if (!id) {
return <DraftNote onPublished={(publishedId) => setParams({ id: publishedId })} />;
return <DraftNote onPublished={(publishedId) => setParams({ ...params, id: publishedId })} />;
}
if (note.isLoading) {