@widgetic/chat 0.1.9 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1331,7 +1331,20 @@
|
|
|
1331
1331
|
if (localHasHead && !loadedHasHead) {
|
|
1332
1332
|
// chatLog('[Chat] Keep local HEAD commit message — DB reload has no commit yet');
|
|
1333
1333
|
} else {
|
|
1334
|
-
|
|
1334
|
+
// DB may lag behind the live session: the backend persists the codegen
|
|
1335
|
+
// summary asynchronously, so a reload fired shortly after generation can
|
|
1336
|
+
// still miss the newest commit. Only adopt the reload when it would not
|
|
1337
|
+
// regress the local HEAD to a different (older) commit.
|
|
1338
|
+
const localHeadSha = extractLatestLocalCommitSha(localMsgs);
|
|
1339
|
+
const loadedHeadSha = extractLatestLocalCommitSha(loaded);
|
|
1340
|
+
const wouldRegressHead =
|
|
1341
|
+
!!localHeadSha
|
|
1342
|
+
&& (!loadedHeadSha || !loadedHeadSha.toLowerCase().startsWith(localHeadSha.slice(0, 7).toLowerCase()));
|
|
1343
|
+
if (wouldRegressHead) {
|
|
1344
|
+
// chatLog('[Chat] Keep local messages — DB reload would regress HEAD commit');
|
|
1345
|
+
} else {
|
|
1346
|
+
chatStore.actions.setMessages(currentConversationId, loaded);
|
|
1347
|
+
}
|
|
1335
1348
|
}
|
|
1336
1349
|
}
|
|
1337
1350
|
markWidgetHeadAtLatestCommit();
|
|
@@ -1341,6 +1354,16 @@
|
|
|
1341
1354
|
}
|
|
1342
1355
|
}
|
|
1343
1356
|
|
|
1357
|
+
/** Newest commit SHA present in a message list (local session or DB reload). */
|
|
1358
|
+
function extractLatestLocalCommitSha(msgs: Array<{ messageContent?: string | null }> | null | undefined): string | null {
|
|
1359
|
+
if (!msgs) return null;
|
|
1360
|
+
for (let i = msgs.length - 1; i >= 0; i--) {
|
|
1361
|
+
const sha = extractCommitShaFromContent(msgs[i]?.messageContent || '');
|
|
1362
|
+
if (sha) return sha;
|
|
1363
|
+
}
|
|
1364
|
+
return null;
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1344
1367
|
function clearStalePreviewBuildFailures() {
|
|
1345
1368
|
if (!currentConversationId) return;
|
|
1346
1369
|
const msgs = getCurrentMessages(currentConversationId);
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { AttachmentDisplay, SuggestionButtons } from './index.js';
|
|
6
6
|
import CodeBlock from './CodeBlock.svelte';
|
|
7
7
|
import LoadingIndicator from './LoadingIndicator.svelte';
|
|
8
|
-
import { onMount, tick } from 'svelte';
|
|
8
|
+
import { onDestroy, onMount, tick } from 'svelte';
|
|
9
9
|
|
|
10
10
|
// Props
|
|
11
11
|
interface Props {
|
|
@@ -422,6 +422,22 @@
|
|
|
422
422
|
let messagesContainer: HTMLElement;
|
|
423
423
|
let showSuggestionsInline = $state(false);
|
|
424
424
|
let autoScroll = $state(true);
|
|
425
|
+
/**
|
|
426
|
+
* Opening on a small screen often resizes the container (parent panel layout)
|
|
427
|
+
* AFTER mount, which resets scroll to the top and clips the input below the
|
|
428
|
+
* fold. A ResizeObserver re-pins the view to the bottom whenever the scroll
|
|
429
|
+
* area's box changes, while `autoScroll` is still true (user has not scrolled
|
|
430
|
+
* up). Disconnected on destroy.
|
|
431
|
+
*/
|
|
432
|
+
let containerResizeObserver: ResizeObserver | null = null;
|
|
433
|
+
|
|
434
|
+
function scrollToBottomInstant(): void {
|
|
435
|
+
if (!messagesContainer) return;
|
|
436
|
+
messagesContainer.scrollTo({
|
|
437
|
+
top: messagesContainer.scrollHeight,
|
|
438
|
+
behavior: 'instant',
|
|
439
|
+
});
|
|
440
|
+
}
|
|
425
441
|
|
|
426
442
|
// Auto-scroll to bottom when new messages arrive or on initial load.
|
|
427
443
|
// Also scrolls on mount/conversation-switch when messages are already present.
|
|
@@ -440,11 +456,24 @@
|
|
|
440
456
|
onMount(() => {
|
|
441
457
|
tick().then(() => {
|
|
442
458
|
if (messagesContainer && visibleMessages.length > 0) {
|
|
443
|
-
|
|
459
|
+
scrollToBottomInstant();
|
|
460
|
+
}
|
|
461
|
+
// Re-pin after late container resizes (panel open animation, parent
|
|
462
|
+
// layout settling, height restored from prefs).
|
|
463
|
+
if (messagesContainer && typeof ResizeObserver !== 'undefined') {
|
|
464
|
+
containerResizeObserver = new ResizeObserver(() => {
|
|
465
|
+
if (autoScroll) scrollToBottomInstant();
|
|
466
|
+
});
|
|
467
|
+
containerResizeObserver.observe(messagesContainer);
|
|
444
468
|
}
|
|
445
469
|
});
|
|
446
470
|
});
|
|
447
471
|
|
|
472
|
+
onDestroy(() => {
|
|
473
|
+
containerResizeObserver?.disconnect();
|
|
474
|
+
containerResizeObserver = null;
|
|
475
|
+
});
|
|
476
|
+
|
|
448
477
|
function handleScroll() {
|
|
449
478
|
if (!messagesContainer) return;
|
|
450
479
|
const { scrollTop, scrollHeight, clientHeight } = messagesContainer;
|