Skip to content

Commit 67d4627

Browse files
fix(web): stabilize composer cost props and test effects
1 parent 1f0ed16 commit 67d4627

2 files changed

Lines changed: 21 additions & 11 deletions

File tree

‎apps/web/src/components/chat/ChatComposer.tsx‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,21 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
14891489
onExpandImage,
14901490
onFileOpen,
14911491
} = props;
1492+
const threadCostId = activeThread?.id;
1493+
const threadCostCreatedAt = activeThread?.createdAt;
1494+
const threadCostRefreshKey = activeContextWindow?.updatedAt ?? null;
1495+
const threadCost = useMemo(
1496+
() =>
1497+
threadCostId === undefined || threadCostCreatedAt === undefined
1498+
? null
1499+
: {
1500+
environmentId,
1501+
threadId: threadCostId,
1502+
createdAt: threadCostCreatedAt,
1503+
refreshKey: threadCostRefreshKey,
1504+
},
1505+
[environmentId, threadCostId, threadCostCreatedAt, threadCostRefreshKey],
1506+
);
14921507
const activeTasksProgress = props.threadSyncPhase === null ? props.activeTasksProgress : null;
14931508
const activeTaskSteps = props.threadSyncPhase === null ? props.activeTaskSteps : null;
14941509
// ------------------------------------------------------------------
@@ -5855,16 +5870,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
58555870
) : null}
58565871
<ComposerFooterPrimaryActions
58575872
compact={isComposerResting || isComposerPrimaryActionsCompact}
5858-
threadCost={
5859-
activeThread
5860-
? {
5861-
environmentId,
5862-
threadId: activeThread.id,
5863-
createdAt: activeThread.createdAt,
5864-
refreshKey: activeContextWindow?.updatedAt ?? null,
5865-
}
5866-
: null
5867-
}
5873+
threadCost={threadCost}
58685874
activeContextWindow={
58695875
settings.contextWindowMeterEnabled ? activeContextWindow : null
58705876
}

‎apps/web/src/state/threadCost.test.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { EnvironmentId, ThreadId, UsageDay, type UsageThreadRow } from "@t3tools/contracts";
22
import { act, createElement } from "react";
33
import { create, type ReactTestRenderer } from "react-test-renderer";
4-
import { afterEach, describe, expect, it, vi } from "vite-plus/test";
4+
import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
55

66
import {
77
makeThreadCostInput,
@@ -30,6 +30,10 @@ vi.mock("./server", () => ({
3030
const threadId = ThreadId.make("thread-cost-test");
3131
let renderer: ReactTestRenderer | undefined;
3232

33+
beforeEach(() => {
34+
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
35+
});
36+
3337
afterEach(async () => {
3438
await act(() => renderer?.unmount());
3539
renderer = undefined;

0 commit comments

Comments
 (0)