Skip to content

Commit a4e23a2

Browse files
committed
Revert "Fix follow up message on shared conversation (#1963)"
This reverts commit 9642080.
1 parent a129a8c commit a4e23a2

File tree

1 file changed

+30
-31
lines changed

1 file changed

+30
-31
lines changed

src/routes/conversation/[id]/+page.svelte

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { isAborted } from "$lib/stores/isAborted";
55
import { onMount } from "svelte";
66
import { page } from "$app/state";
7-
import { beforeNavigate, invalidateAll, replaceState } from "$app/navigation";
7+
import { beforeNavigate, goto, invalidateAll } from "$app/navigation";
88
import { base } from "$app/paths";
99
import { ERROR_MESSAGES, error } from "$lib/stores/errors";
1010
import { findCurrentModel } from "$lib/utils/models";
@@ -37,7 +37,6 @@
3737
3838
let files: File[] = $state([]);
3939
40-
let conversationId = page.params.id;
4140
let conversations = $state(data.conversations);
4241
$effect(() => {
4342
conversations = data.conversations;
@@ -242,7 +241,7 @@
242241
const messageUpdatesAbortController = new AbortController();
243242
244243
const messageUpdatesIterator = await fetchMessageUpdates(
245-
conversationId,
244+
page.params.id,
246245
{
247246
base,
248247
inputs: prompt,
@@ -303,13 +302,13 @@
303302
$error = update.message ?? "An error has occurred";
304303
}
305304
} else if (update.type === MessageUpdateType.Title) {
306-
const convInData = conversations.find(({ id }) => id === conversationId);
305+
const convInData = conversations.find(({ id }) => id === page.params.id);
307306
if (convInData) {
308307
convInData.title = update.title;
309308
310309
$titleUpdate = {
311310
title: update.title,
312-
convId: conversationId,
311+
convId: page.params.id,
313312
};
314313
}
315314
} else if (update.type === MessageUpdateType.File) {
@@ -344,7 +343,7 @@
344343
}
345344
346345
async function stopGeneration() {
347-
await fetch(`${base}/conversation/${conversationId}/stop-generating`, {
346+
await fetch(`${base}/conversation/${page.params.id}/stop-generating`, {
348347
method: "POST",
349348
}).then((r) => {
350349
if (r.ok) {
@@ -368,7 +367,6 @@
368367
}
369368
370369
onMount(async () => {
371-
conversationId = page.params.id;
372370
if ($pendingMessage) {
373371
files = $pendingMessage.files;
374372
await writeMessage({ prompt: $pendingMessage.content });
@@ -377,7 +375,7 @@
377375
378376
const streaming = isConversationStreaming(messages);
379377
if (streaming) {
380-
addBackgroundGeneration({ id: conversationId, startedAt: Date.now() });
378+
addBackgroundGeneration({ id: page.params.id, startedAt: Date.now() });
381379
$loading = true;
382380
}
383381
});
@@ -386,13 +384,12 @@
386384
if (!data.shared) {
387385
await writeMessage({ prompt: content });
388386
} else {
389-
try {
390-
conversationId = await convFromShared();
391-
replaceState(`${base}/conversation/${conversationId}`, page.state);
392-
await writeMessage({ prompt: content });
393-
} finally {
394-
$loading = false;
395-
}
387+
await convFromShared()
388+
.then(async (convId) => {
389+
await goto(`${base}/conversation/${convId}`, { invalidateAll: true });
390+
})
391+
.then(async () => await writeMessage({ prompt: content }))
392+
.finally(() => ($loading = false));
396393
}
397394
}
398395
@@ -409,17 +406,19 @@
409406
isRetry: true,
410407
});
411408
} else {
412-
try {
413-
const conversationId = await convFromShared();
414-
replaceState(`${base}/conversation/${conversationId}`, page.state);
415-
await writeMessage({
416-
prompt: payload.content,
417-
messageId: payload.id,
418-
isRetry: true,
419-
});
420-
} finally {
421-
$loading = false;
422-
}
409+
await convFromShared()
410+
.then(async (convId) => {
411+
await goto(`${base}/conversation/${convId}`, { invalidateAll: true });
412+
})
413+
.then(
414+
async () =>
415+
await writeMessage({
416+
prompt: payload.content,
417+
messageId: payload.id,
418+
isRetry: true,
419+
})
420+
)
421+
.finally(() => ($loading = false));
423422
}
424423
}
425424
@@ -457,7 +456,7 @@
457456
}
458457
459458
if (!streaming && browser) {
460-
removeBackgroundGeneration(conversationId);
459+
removeBackgroundGeneration(page.params.id);
461460
}
462461
});
463462
@@ -472,21 +471,21 @@
472471
});
473472
474473
beforeNavigate((navigation) => {
475-
if (!conversationId) return;
474+
if (!page.params.id) return;
476475
477476
const navigatingAway =
478-
navigation.to?.route.id !== page.route.id || navigation.to?.params?.id !== conversationId;
477+
navigation.to?.route.id !== page.route.id || navigation.to?.params?.id !== page.params.id;
479478
480479
if (loading && navigatingAway) {
481-
addBackgroundGeneration({ id: conversationId, startedAt: Date.now() });
480+
addBackgroundGeneration({ id: page.params.id, startedAt: Date.now() });
482481
}
483482
484483
$isAborted = true;
485484
$loading = false;
486485
});
487486
488487
let title = $derived.by(() => {
489-
const rawTitle = conversations.find((conv) => conv.id === conversationId)?.title ?? data.title;
488+
const rawTitle = conversations.find((conv) => conv.id === page.params.id)?.title ?? data.title;
490489
return rawTitle ? rawTitle.charAt(0).toUpperCase() + rawTitle.slice(1) : rawTitle;
491490
});
492491
</script>

0 commit comments

Comments
 (0)