Changesets · Branches · Tags · Compare
| Changeset | dab1b70f3082a6de479dd98c6a2c7eccdd8111668e3ad12e4c72b4c265ebd1e1 |
|---|---|
| Author | Nate <sestinj@gmail.com> · 2025-08-31 16:32 -07:00 |
| Committer | Nate <sestinj@gmail.com> · 2025-08-31 16:32 -07:00 |
| Parents | bdd98e6744b8 |
4 files changed
modified extensions/cli/src/ui/IntroMessage.test.tsx +2 −1
| @@ -1,12 +1,13 @@ | ||
| 1 | 1 | import { render } from "ink-testing-library"; |
| 2 | 2 | import React from "react"; |
| 3 | +import { Text } from "ink"; | |
| 3 | 4 | import { describe, it, expect, vi, beforeEach, afterEach } from "vitest"; |
| 4 | 5 | |
| 5 | 6 | import { IntroMessage } from "./IntroMessage.js"; |
| 6 | 7 | |
| 7 | 8 | // Mock the TipsDisplay module |
| 8 | 9 | vi.mock("./TipsDisplay.js", () => ({ |
| 9 | - TipsDisplay: () => React.createElement("div", null, "Mocked TipsDisplay"), | |
| 10 | + TipsDisplay: () => React.createElement(Text, null, "Mocked TipsDisplay"), | |
| 10 | 11 | shouldShowTip: vi.fn(), |
| 11 | 12 | })); |
| 12 | 13 |
modified extensions/cli/src/ui/IntroMessage.tsx +6 −6
| @@ -30,8 +30,11 @@ | ||
| 30 | 30 | // Get MCP prompts directly (not memoized since they can change after first render) |
| 31 | 31 | const mcpPrompts = mcpService?.getState().prompts ?? []; |
| 32 | 32 | |
| 33 | + // Determine if we should show a tip (1 in 5 chance) - computed once on mount | |
| 34 | + const showTip = useMemo(() => shouldShowTip(), []); | |
| 35 | + | |
| 33 | 36 | // Memoize expensive operations to avoid running on every resize |
| 34 | - const { allRules, modelCapable, showTip } = useMemo(() => { | |
| 37 | + const { allRules, modelCapable } = useMemo(() => { | |
| 35 | 38 | const allRules = extractRuleNames(config?.rules); |
| 36 | 39 | |
| 37 | 40 | // Check if model is capable - now checking both name and model properties |
| @@ -39,10 +42,7 @@ | ||
| 39 | 42 | ? isModelCapable(model.provider, model.name, model.model) |
| 40 | 43 | : true; // Default to true if model not loaded yet |
| 41 | 44 | |
| 42 | - // Determine if we should show a tip (1 in 5 chance) | |
| 43 | - const showTip = shouldShowTip(); | |
| 44 | - | |
| 45 | - return { allRules, modelCapable, showTip }; | |
| 45 | + return { allRules, modelCapable }; | |
| 46 | 46 | }, [config?.rules, model?.provider, model?.name, model?.model]); |
| 47 | 47 | |
| 48 | 48 | // Render helper components |
| @@ -96,7 +96,7 @@ | ||
| 96 | 96 | <Text> </Text> |
| 97 | 97 | |
| 98 | 98 | {/* Tips Display - shown randomly 1 in 5 times */} |
| 99 | - {showTip ? <TipsDisplay /> : <Text>nah</Text>} | |
| 99 | + {showTip && <TipsDisplay />} | |
| 100 | 100 | |
| 101 | 101 | {/* Agent name */} |
| 102 | 102 | {config && ( |
modified extensions/cli/src/ui/TipsDisplay.test.tsx +1 −1
| @@ -138,7 +138,7 @@ | ||
| 138 | 138 | "/resume", |
| 139 | 139 | "headless", |
| 140 | 140 | "flag", |
| 141 | - "keyboard shortcuts" | |
| 141 | + "keyboard shortcuts", | |
| 142 | 142 | ]; |
| 143 | 143 | |
| 144 | 144 | const allTipsText = CONTINUE_CLI_TIPS.join(" ").toLowerCase(); |
modified extensions/cli/src/ui/TipsDisplay.tsx +7 −4
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | import { Box, Text } from "ink"; |
| 2 | -import React from "react"; | |
| 2 | +import React, { useMemo } from "react"; | |
| 3 | 3 | |
| 4 | 4 | // Array of helpful tips for Continue CLI users |
| 5 | 5 | const CONTINUE_CLI_TIPS = [ |
| @@ -20,9 +20,12 @@ | ||
| 20 | 20 | * Should only be shown 1 in 5 times (20% chance). |
| 21 | 21 | */ |
| 22 | 22 | const TipsDisplay: React.FC<TipsDisplayProps> = () => { |
| 23 | - // Randomly select a tip | |
| 24 | - const randomTip = | |
| 25 | - CONTINUE_CLI_TIPS[Math.floor(Math.random() * CONTINUE_CLI_TIPS.length)]; | |
| 23 | + // Randomly select a tip, memoized to prevent changing on re-renders | |
| 24 | + const randomTip = useMemo( | |
| 25 | + () => | |
| 26 | + CONTINUE_CLI_TIPS[Math.floor(Math.random() * CONTINUE_CLI_TIPS.length)], | |
| 27 | + [], | |
| 28 | + ); | |
| 26 | 29 | |
| 27 | 30 | return ( |
| 28 | 31 | <Box flexDirection="row" paddingX={1} paddingBottom={1}> |