fix(webui): navigate from history to unsaved live prompts

This commit is contained in:
Xubin Ren committed 2026-10-18 17:13:18 +08:00
1 parent f9a3e55b64
commit f230409b5a
2 files changed
+19 -3

No files matched your search

@@ -534,13 +534,15 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
navigation.jump(promptId);
return;
}
const index = messages.findIndex((message) => message.id === promptId);
const localMessages = historyWindow ? latestMessages : messages;
const index = localMessages.findIndex((message) => message.id === promptId);
if (index < 0) return;
if (historyWindow) navigation?.latest();
threadMotionRef.current?.takeUserControl();
pendingPromptJumpRef.current = promptId;
setAtBottom(false);
setVisibleMessageCount((count) => Math.max(count, messages.length - index));
}, [messages, navigateToVisiblePrompt, navigation]);
setVisibleMessageCount((count) => Math.max(count, localMessages.length - index));
}, [historyWindow, latestMessages, messages, navigateToVisiblePrompt, navigation]);
useLayoutEffect(() => {
if (!navigation?.target) return;
+14
View File
@@ -1989,6 +1989,20 @@ describe("ThreadViewport", () => {
await waitFor(() => expect(screen.getByText("message 20")).toBeInTheDocument());
});
it("returns from a history window to a live prompt that has no saved cursor yet", async () => {
const viewportRef = createRef<ThreadViewportHandle>();
const latest = vi.fn();
const navigation = { prompts: [{ id: "u1", label: "hello", preview: "hello", answerPreview: "", createdAt: 1, index: 0 }],
window: { messages: [{ id: "old", role: "user" as const, content: "old question", createdAt: 0 }],
userMessageOffset: 0, hasMoreBefore: false, hasMoreAfter: true, forkBoundaryMessageCount: null },
target: null, loading: false, error: null, jump: vi.fn(), older: vi.fn(), newer: vi.fn(), latest, retry: vi.fn(), updateMessages: vi.fn() };
const view = render(<ThreadViewport ref={viewportRef} messages={messages} isStreaming={false} composer={<div />} navigation={navigation} />);
act(() => viewportRef.current?.jumpToUserPrompt("u1"));
expect(latest).toHaveBeenCalledOnce();
view.rerender(<ThreadViewport ref={viewportRef} messages={messages} isStreaming={false} composer={<div />} navigation={{ ...navigation, window: null }} />);
await waitFor(() => expect(screen.getByText("hello")).toBeInTheDocument());
});
it("includes the selected prompt when one server turn exceeds the local render window", async () => {
const history: UIMessage[] = [{ id: "old-user", role: "user", content: "Large old turn", createdAt: 1 },
...Array.from({ length: INITIAL_HISTORY_WINDOW + 10 }, (_, index): UIMessage => ({