fix(webui): stabilize earlier-history loading and reclaim space (#6349)

* fix(webui): retain smoothly revealed history loading headers

* refactor(webui): simplify history loading feedback

* fix(webui): keep retained history headers clear of preceding text

* fix(webui): reclaim completed history loading space

* refactor(webui): group history projection handoff with navigation

* test(webui): synchronize history motion observations

* fix(webui): collapse history completion geometry handoff
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-21 13:10:05 +08:00
1 parent 73a55e0b2f
commit 743c51e81f
24 files changed
+1658 -356

No files matched your search

+23 -12
View File
@@ -49,7 +49,7 @@ function dispatchHistoryInput(scroller: HTMLElement, input: "wheel" | "touch" |
if (input === "keyboard") fireEvent.keyDown(scroller, { key: "PageUp" });
if (input === "touch") {
fireEvent.touchStart(scroller, { touches: [{ clientX: 100, clientY: 200 }] });
fireEvent.touchMove(scroller, { touches: [{ clientX: 100, clientY: 300 }] });
fireEvent.touchMove(scroller, { touches: [{ clientX: 100, clientY: 380 }] });
fireEvent.touchEnd(scroller);
}
}
@@ -1517,7 +1517,6 @@ describe("ThreadViewport", () => {
expect(screen.queryByText(`message ${firstVisible - 1}`)).not.toBeInTheDocument();
expect(screen.getByText(`message ${firstVisible}`)).toBeInTheDocument();
expect(screen.getByText("message 299")).toBeInTheDocument();
expect(screen.getByRole("button", { name: "Load earlier messages" })).toBeInTheDocument();
});
it("automatically expands earlier local history near the top", () => {
@@ -1677,7 +1676,6 @@ describe("ThreadViewport", () => {
describe.each(["wheel", "touch"] as const)("%s history boundary", (input) => {
it.each([
{ loadingOlder: true },
{ olderError: "offline" },
{ conversationReady: false },
{ hasMoreBefore: false },
])("keeps history blocked: %o", (blocked) => {
@@ -1714,7 +1712,7 @@ describe("ThreadViewport", () => {
expect(onLoadOlder).toHaveBeenCalledTimes(1);
});
it("pauses automatic history requests after a failure and exposes retry", () => {
it.each(["wheel", "touch", "keyboard"] as const)("pauses automatic requests after failure but accepts another %s boundary gesture", (input) => {
const onLoadOlder = vi.fn();
const { container } = render(
@@ -1737,7 +1735,8 @@ describe("ThreadViewport", () => {
});
expect(onLoadOlder).not.toHaveBeenCalled();
fireEvent.click(screen.getByRole("button", { name: "Loading failed. Retry" }));
expect(screen.getByRole("button", { name: "Loading failed. Retry" }).querySelectorAll(".thread-history-blocks > span")).toHaveLength(9);
dispatchHistoryInput(scroller, input);
expect(onLoadOlder).toHaveBeenCalledTimes(1);
});
@@ -1774,13 +1773,14 @@ describe("ThreadViewport", () => {
fireEvent.touchMove(scroller, touch(240));
expect(historyPull(scroller)).toBeGreaterThan(0);
expect(screen.getByRole("status").querySelectorAll(".thread-history-blocks > span")).toHaveLength(9);
expect(container.querySelector(".thread-history-status")).not.toHaveClass("invisible");
expect(onLoadOlder).not.toHaveBeenCalled();
fireEvent.touchEnd(scroller);
expect(historyPull(scroller)).toBeGreaterThan(0);
await waitFor(() => expect(historyPull(scroller)).toBe(0));
fireEvent.touchStart(scroller, touch(200));
fireEvent.touchMove(scroller, touch(300));
fireEvent.touchMove(scroller, touch(380));
expect(onLoadOlder).not.toHaveBeenCalled();
expect(screen.getByRole("status").querySelectorAll(".thread-history-blocks > span")).toHaveLength(9);
fireEvent.touchEnd(scroller);
@@ -1789,8 +1789,19 @@ describe("ThreadViewport", () => {
fireEvent.scroll(scroller);
expect(onLoadOlder).toHaveBeenCalledTimes(1);
expect(screen.getByText("Loading earlier messages…")).toBeInTheDocument();
rerender(<ThreadViewport {...props} />);
rerender(<ThreadViewport {...props} loadingOlder />);
expect(container.querySelector(".thread-history-slot")).toBeInTheDocument();
const prepended = [
{ ...messages[0], id: "older-u0", content: "Earlier message" },
...messages,
];
rerender(<ThreadViewport {...props} messages={prepended} />);
await waitFor(() => expect(historyPull(scroller)).toBe(0));
expect(container.querySelector(".thread-history-slot")).not.toBeInTheDocument();
expect(container.querySelector(".thread-history-status")).toHaveAttribute("data-state", "ready");
expect(container.querySelector(".thread-history-status")).toHaveClass("invisible");
expect(screen.queryByRole("status")).not.toBeInTheDocument();
expect(screen.queryByText("Loading earlier messages…")).not.toBeInTheDocument();
});
it("does not fetch on touch scroll alone or horizontal gestures and clears pull on session change", () => {
@@ -2009,7 +2020,7 @@ describe("ThreadViewport", () => {
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(), cancel: vi.fn(), latest, retry: vi.fn(), updateMessages: vi.fn() };
target: null, operation: null, loading: false, error: null, jump: vi.fn(), older: vi.fn(), newer: vi.fn(), cancel: 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();
@@ -2025,7 +2036,7 @@ describe("ThreadViewport", () => {
render(<ThreadViewport messages={messages} isStreaming={false} composer={<div />}
navigation={{ prompts: [], window: { messages: history, userMessageOffset: 0,
hasMoreBefore: false, hasMoreAfter: true, forkBoundaryMessageCount: null },
target: { id: "old-user", sequence: 1 }, loading: false, error: null,
target: { id: "old-user", sequence: 1 }, operation: null, loading: false, error: null,
jump: vi.fn(), older: vi.fn(), newer: vi.fn(), cancel: vi.fn(), latest: vi.fn(), retry: vi.fn(), updateMessages: vi.fn() }} />);
await waitFor(() => expect(screen.getByText("Large old turn")).toBeInTheDocument());
});
@@ -2099,17 +2110,17 @@ describe("ThreadViewport", () => {
expect(navigateTo).toHaveBeenLastCalledWith(Math.max(0, (count - 1) * 40 - 48));
});
it("keeps prompt jumps aligned when the header changes between a row and an overlay", async () => {
it("aligns prompt jumps with the scroll inset independently of message layout", async () => {
const navigateTo = vi.spyOn(ThreadCameraController.prototype, "navigateTo")
.mockReturnValue("started");
const { scroller } = await renderPromptRailViewport();
const marker = screen.getByRole("button", { name: "Jump to message: message 1" });
scroller.style.paddingTop = "16px";
scroller.style.scrollPaddingTop = "16px";
fireEvent.click(marker);
expect(navigateTo).toHaveBeenLastCalledWith(344);
scroller.style.paddingTop = "48px";
scroller.style.scrollPaddingTop = "48px";
fireEvent.click(marker);
expect(navigateTo).toHaveBeenLastCalledWith(312);
});