perf(tui): shrink standalone builds and target native bindings (#6432)
* perf(tui): shrink standalone builds without dropping features * fix(tui): resolve macOS diagram fonts through CoreText * fix(webui): preserve history pagination at the page boundary * docs(tui): streamline release preflight guidance --------- Co-authored-by: Xubin Ren <52506698+Re-bin@users.noreply.github.com>
This commit is contained in:
1 parent
0e0df327c8
commit
ae7fed88e2
21 files changed
+424
-82
No files matched your search
@@ -903,7 +903,8 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
|
||||
if (el.scrollTop > 1) historySpringRef.current?.leaveBoundary();
|
||||
const distance = el.scrollHeight - el.scrollTop - el.clientHeight;
|
||||
const near = distance < NEAR_BOTTOM_PX;
|
||||
const owner = threadMotionRef.current?.observeScroll(near) ?? "automatic";
|
||||
// A detached history page's bottom is not the live tail.
|
||||
const owner = threadMotionRef.current?.observeScroll(near && !historyWindow) ?? "automatic";
|
||||
const logicallyAtBottom = !historyWindow && (owner === "automatic" || (owner === "navigation" && near));
|
||||
setAtBottom((current) =>
|
||||
current === logicallyAtBottom ? current : logicallyAtBottom,
|
||||
@@ -942,7 +943,7 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
|
||||
}
|
||||
threadMotionRef.current?.handleUserScrollIntent(
|
||||
canScrollInDirection(el, direction),
|
||||
direction === "forward",
|
||||
direction === "forward" && !historyWindow,
|
||||
);
|
||||
};
|
||||
const prepareHistoryPull = () => {
|
||||
@@ -1026,11 +1027,7 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
|
||||
setAtHistoryTop(true);
|
||||
return;
|
||||
}
|
||||
// Locally windowed messages need no network gesture or loading feedback.
|
||||
if (hiddenMessageCount > 0) handleDirectionalInput(directionFromDelta(delta));
|
||||
else threadMotionRef.current?.handleUserScrollIntent(
|
||||
canScrollInDirection(el, directionFromDelta(delta)), delta > 0,
|
||||
);
|
||||
handleDirectionalInput(directionFromDelta(delta));
|
||||
};
|
||||
const handleTouchEnd = () => {
|
||||
const pulling = historyTouchRef.current?.pulling;
|
||||
|
||||
@@ -342,13 +342,14 @@ export class ThreadMotionCoordinator {
|
||||
* A scroll event reports geometry; it does not prove user intent. Explicit
|
||||
* input handlers call takeUserControl() before the browser scrolls. Layout,
|
||||
* sticky positioning, and camera writes therefore remain automatic even
|
||||
* when the browser emits an intermediate scroll event for them.
|
||||
* when the browser emits an intermediate scroll event for them. Proximity
|
||||
* to a detached history page's bottom must not count as near the live tail.
|
||||
*/
|
||||
observeScroll(nearBottom: boolean): ThreadScrollOwner {
|
||||
observeScroll(nearLiveTail: boolean): ThreadScrollOwner {
|
||||
switch (this.mode) {
|
||||
case "navigating-latest":
|
||||
if (!this.camera.isFollowing()) {
|
||||
if (nearBottom) {
|
||||
if (nearLiveTail) {
|
||||
this.settleLatestNavigation();
|
||||
} else {
|
||||
this.invalidateGeometry();
|
||||
@@ -358,7 +359,7 @@ export class ThreadMotionCoordinator {
|
||||
case "navigating-history":
|
||||
if (!this.camera.isFollowing()) {
|
||||
this.transition("navigation-settled");
|
||||
if (nearBottom) {
|
||||
if (nearLiveTail) {
|
||||
this.resumeAutoFollow();
|
||||
} else {
|
||||
this.resumeFollowArmed = true;
|
||||
@@ -366,7 +367,7 @@ export class ThreadMotionCoordinator {
|
||||
}
|
||||
return "navigation";
|
||||
case "browsing-history":
|
||||
if (!nearBottom) {
|
||||
if (!nearLiveTail) {
|
||||
this.resumeFollowArmed = true;
|
||||
return "user";
|
||||
}
|
||||
@@ -374,7 +375,7 @@ export class ThreadMotionCoordinator {
|
||||
this.resumeAutoFollow();
|
||||
return "automatic";
|
||||
default:
|
||||
if (!nearBottom) this.invalidateGeometry();
|
||||
if (!nearLiveTail) this.invalidateGeometry();
|
||||
return "automatic";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
} from "@/components/thread/ThreadViewport";
|
||||
import { ThreadCameraController } from "@/components/thread/thread-camera";
|
||||
import { ThreadMotionCoordinator } from "@/components/thread/thread-motion";
|
||||
import type { PromptHistoryNavigation } from "@/hooks/usePromptHistory";
|
||||
import type { UIMessage } from "@/lib/types";
|
||||
|
||||
const messages: UIMessage[] = [
|
||||
@@ -2028,6 +2029,56 @@ describe("ThreadViewport", () => {
|
||||
await waitFor(() => expect(screen.getByText("hello")).toBeInTheDocument());
|
||||
});
|
||||
|
||||
it.each(["wheel", "touch", "keyboard"] as const)("loads newer history after one %s input reaches the page bottom", async (input) => {
|
||||
const history = makePromptExchangeMessages(5);
|
||||
const newer = vi.fn();
|
||||
const navigation: PromptHistoryNavigation = {
|
||||
prompts: [], window: { messages: history, userMessageOffset: 0,
|
||||
hasMoreBefore: false, hasMoreAfter: true, forkBoundaryMessageCount: null },
|
||||
target: null, operation: null, loading: false, error: null,
|
||||
jump: vi.fn(), older: vi.fn(), newer, cancel: vi.fn(), latest: vi.fn(), retry: vi.fn(), updateMessages: vi.fn(),
|
||||
};
|
||||
const view = render(<ThreadViewport messages={messages} isStreaming={false} composer={<div />} navigation={navigation} />);
|
||||
await flushAnimationFrame();
|
||||
const scroller = view.getByTestId("thread-message-region");
|
||||
mockScrollGeometry(scroller, 2000, 500, 100);
|
||||
|
||||
const forward = () => {
|
||||
if (input === "wheel") fireEvent.wheel(scroller, { deltaY: 10000 });
|
||||
if (input === "keyboard") fireEvent.keyDown(scroller, { key: "End" });
|
||||
if (input === "touch") {
|
||||
fireEvent.touchStart(scroller, { touches: [{ clientX: 100, clientY: 400 }] });
|
||||
fireEvent.touchMove(scroller, { touches: [{ clientX: 100, clientY: 200 }] });
|
||||
fireEvent.touchEnd(scroller);
|
||||
}
|
||||
};
|
||||
// A large input can cross the entire prefetch range in one native scroll.
|
||||
forward();
|
||||
expect(newer).not.toHaveBeenCalled();
|
||||
act(() => {
|
||||
scroller.scrollTop = 1500;
|
||||
fireEvent.scroll(scroller);
|
||||
});
|
||||
expect(newer).toHaveBeenCalledOnce();
|
||||
|
||||
// Appending a page must preserve the reader's position, not follow its tail.
|
||||
mockScrollGeometry(scroller, 2800, 500, 1500);
|
||||
view.rerender(<ThreadViewport messages={messages} isStreaming={false} composer={<div />}
|
||||
navigation={{ ...navigation, window: { ...navigation.window!, messages: makePromptExchangeMessages(10) } }} />);
|
||||
await flushAnimationFrame();
|
||||
expect(scroller.scrollTop).toBe(1500);
|
||||
|
||||
// At the existing page boundary, forward input cannot produce a scroll event.
|
||||
mockScrollGeometry(scroller, 2800, 500, 2300);
|
||||
forward();
|
||||
expect(newer).toHaveBeenCalledTimes(2);
|
||||
mockScrollGeometry(scroller, 3600, 500, 2300);
|
||||
view.rerender(<ThreadViewport messages={messages} isStreaming={false} composer={<div />}
|
||||
navigation={{ ...navigation, window: { ...navigation.window!, messages: makePromptExchangeMessages(15) } }} />);
|
||||
await flushAnimationFrame();
|
||||
expect(scroller.scrollTop).toBe(2300);
|
||||
});
|
||||
|
||||
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 => ({
|
||||
|
||||
Reference in new issue
Block a user