mirror of
https://github.com/layer-systems/website.git
synced 2026-09-12 21:53:40 +02:00
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:
@@ -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('');
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user