mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-04-29 04:00:36 +00:00
perf(cli): memoize btw message component
This commit is contained in:
parent
bd77eef46f
commit
130d6888b4
2 changed files with 38 additions and 2 deletions
34
packages/cli/src/ui/components/messages/BtwMessage.test.tsx
Normal file
34
packages/cli/src/ui/components/messages/BtwMessage.test.tsx
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/**
|
||||
* @license
|
||||
* Copyright 2025 Qwen Code
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { render } from 'ink-testing-library';
|
||||
import { BtwMessage } from './BtwMessage.js';
|
||||
|
||||
describe('BtwMessage', () => {
|
||||
it('is wrapped in React.memo to avoid unnecessary layout rerenders', () => {
|
||||
expect((BtwMessage as unknown as { $$typeof?: symbol }).$$typeof).toBe(
|
||||
Symbol.for('react.memo'),
|
||||
);
|
||||
});
|
||||
|
||||
it('renders the side question and answer', () => {
|
||||
const { lastFrame } = render(
|
||||
<BtwMessage
|
||||
btw={{
|
||||
question: 'side question',
|
||||
answer: 'side answer',
|
||||
isPending: false,
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
|
||||
const output = lastFrame() ?? '';
|
||||
expect(output).toContain('/btw');
|
||||
expect(output).toContain('side question');
|
||||
expect(output).toContain('side answer');
|
||||
});
|
||||
});
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import type React from 'react';
|
||||
import React from 'react';
|
||||
import { Box, Text } from 'ink';
|
||||
import type { BtwProps } from '../../types.js';
|
||||
import { Colors } from '../../colors.js';
|
||||
|
|
@ -14,7 +14,7 @@ export interface BtwDisplayProps {
|
|||
btw: BtwProps;
|
||||
}
|
||||
|
||||
export const BtwMessage: React.FC<BtwDisplayProps> = ({ btw }) => (
|
||||
const BtwMessageInternal: React.FC<BtwDisplayProps> = ({ btw }) => (
|
||||
<Box
|
||||
flexDirection="column"
|
||||
borderStyle="round"
|
||||
|
|
@ -45,3 +45,5 @@ export const BtwMessage: React.FC<BtwDisplayProps> = ({ btw }) => (
|
|||
)}
|
||||
</Box>
|
||||
);
|
||||
|
||||
export const BtwMessage = React.memo(BtwMessageInternal);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue