Merge pull request #177 from continuedev/fix-rerenders
fix: use static to avoid rerenders
This commit is contained in:
commit
2c8ea87b0e
4 changed files with 98 additions and 17 deletions
7
.github/workflows/pr_checks.yml
vendored
7
.github/workflows/pr_checks.yml
vendored
|
|
@ -43,6 +43,13 @@ jobs:
|
|||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Debug environment info
|
||||
run: |
|
||||
echo "Node.js version: $(node --version)"
|
||||
echo "npm version: $(npm --version)"
|
||||
echo "Prettier version: $(npx prettier --version)"
|
||||
echo "Platform: $(uname -a)"
|
||||
|
||||
- name: Check code formatting
|
||||
run: npm run format:check
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import os from "node:os";
|
||||
|
||||
import * as node_machine_id from 'node-machine-id';
|
||||
import * as node_machine_id from "node-machine-id";
|
||||
import type { PostHog as PostHogType } from "posthog-node";
|
||||
|
||||
import { loadAuthConfig, isAuthenticatedConfig } from "../auth/workos.js";
|
||||
import { isAuthenticatedConfig, loadAuthConfig } from "../auth/workos.js";
|
||||
|
||||
export class PosthogService {
|
||||
export class PosthogService {
|
||||
private os: string | undefined;
|
||||
private uniqueId: string;
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import {
|
|||
import { getGitRemoteUrl, isGitRepo } from "../util/git.js";
|
||||
|
||||
import { ModeIndicator } from "./components/ModeIndicator.js";
|
||||
import { StaticChatContent } from "./components/StaticChatContent.js";
|
||||
import { ToolPermissionSelector } from "./components/ToolPermissionSelector.js";
|
||||
import { ConfigSelector } from "./ConfigSelector.js";
|
||||
import { useNavigation } from "./context/NavigationContext.js";
|
||||
|
|
@ -25,7 +26,6 @@ import { useConfigSelector } from "./hooks/useConfigSelector.js";
|
|||
import { useMessageRenderer } from "./hooks/useMessageRenderer.js";
|
||||
import { useModelSelector } from "./hooks/useModelSelector.js";
|
||||
import { useOrganizationSelector } from "./hooks/useOrganizationSelector.js";
|
||||
import { IntroMessage } from "./IntroMessage.js";
|
||||
import { LoadingAnimation } from "./LoadingAnimation.js";
|
||||
import { ModelSelector } from "./ModelSelector.js";
|
||||
import { OrganizationSelector } from "./OrganizationSelector.js";
|
||||
|
|
@ -241,19 +241,15 @@ const TUIChat: React.FC<TUIChatProps> = ({
|
|||
/>
|
||||
)} */}
|
||||
|
||||
{/* Show intro message when ready */}
|
||||
{showIntroMessage &&
|
||||
!isRemoteMode &&
|
||||
services.config?.config &&
|
||||
services.model?.model &&
|
||||
services.mcp?.mcpService && (
|
||||
<IntroMessage
|
||||
config={services.config.config}
|
||||
model={services.model.model}
|
||||
mcpService={services.mcp.mcpService}
|
||||
/>
|
||||
)}
|
||||
{messages.map(renderMessage)}
|
||||
{/* Chat content with intro message and messages in static container */}
|
||||
<StaticChatContent
|
||||
showIntroMessage={showIntroMessage && !isRemoteMode}
|
||||
config={services.config?.config || undefined}
|
||||
model={services.model?.model || undefined}
|
||||
mcpService={services.mcp?.mcpService || undefined}
|
||||
messages={messages}
|
||||
renderMessage={renderMessage}
|
||||
/>
|
||||
</Box>
|
||||
|
||||
{/* Fixed bottom section */}
|
||||
|
|
|
|||
78
src/ui/components/StaticChatContent.tsx
Normal file
78
src/ui/components/StaticChatContent.tsx
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
import type { AssistantUnrolled, ModelConfig } from "@continuedev/config-yaml";
|
||||
import { Static } from "ink";
|
||||
import React from "react";
|
||||
|
||||
import type { MCPService } from "../../mcp.js";
|
||||
import { useTerminalSize } from "../hooks/useTerminalSize.js";
|
||||
import { IntroMessage } from "../IntroMessage.js";
|
||||
import type { DisplayMessage } from "../types.js";
|
||||
|
||||
interface StaticChatContentProps {
|
||||
showIntroMessage: boolean;
|
||||
config?: AssistantUnrolled;
|
||||
model?: ModelConfig;
|
||||
mcpService?: MCPService;
|
||||
messages: DisplayMessage[];
|
||||
renderMessage: (message: DisplayMessage, index: number) => React.ReactElement;
|
||||
}
|
||||
|
||||
export const StaticChatContent: React.FC<StaticChatContentProps> = ({
|
||||
showIntroMessage,
|
||||
config,
|
||||
model,
|
||||
mcpService,
|
||||
messages,
|
||||
renderMessage,
|
||||
}) => {
|
||||
const { columns } = useTerminalSize();
|
||||
// Create a combined array of items to render
|
||||
const staticItems = React.useMemo(() => {
|
||||
const items: Array<{
|
||||
type: "intro" | "message";
|
||||
data: DisplayMessage | null;
|
||||
index?: number;
|
||||
}> = [];
|
||||
|
||||
// Add intro message as first item if it should be shown
|
||||
if (showIntroMessage && config && model && mcpService) {
|
||||
items.push({ type: "intro", data: null });
|
||||
}
|
||||
|
||||
// Add all chat messages
|
||||
messages.forEach((message, index) => {
|
||||
items.push({ type: "message", data: message, index });
|
||||
});
|
||||
|
||||
return items;
|
||||
}, [showIntroMessage, config, model, mcpService, messages]);
|
||||
|
||||
return (
|
||||
<Static
|
||||
items={staticItems}
|
||||
style={{
|
||||
width: columns - 1,
|
||||
textWrap: "wrap",
|
||||
}}
|
||||
>
|
||||
{(item) => {
|
||||
if (item.type === "intro" && config && model && mcpService) {
|
||||
return (
|
||||
<IntroMessage
|
||||
key="intro"
|
||||
config={config}
|
||||
model={model}
|
||||
mcpService={mcpService}
|
||||
/>
|
||||
);
|
||||
} else if (
|
||||
item.type === "message" &&
|
||||
item.data &&
|
||||
item.index !== undefined
|
||||
) {
|
||||
return renderMessage(item.data, item.index);
|
||||
}
|
||||
return null;
|
||||
}}
|
||||
</Static>
|
||||
);
|
||||
};
|
||||
Loading…
Add table
Reference in a new issue