Skip to content

Commit

Permalink
🐛 fix: 修复窗口特殊情况下不停 Shaking 的问题 (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
ONLY-yours authored Jun 18, 2024
1 parent 5ff3b89 commit 854432d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/ProChat/__test__/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { gLocaleObject } from '@/locale';
import { fireEvent, render, waitFor } from '@testing-library/react';
import { describe, it, vi } from 'vitest';
import { ProChat } from '..';

describe('ProChat', () => {
Expand Down
7 changes: 6 additions & 1 deletion src/ProChat/container/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,12 @@ const App = memo<ConversationProps>(
return (
<RcResizeObserver
onResize={(e) => {
if (e.height !== height) {
if (
typeof height !== typeof e.height ||
(typeof height === 'string' && typeof e.height === 'string' && e.height !== height) ||
(typeof height === 'number' && Math.abs(e.height - height) > 1)
) {
// stop shaking
setHeight(e.height);
}
}}
Expand Down
6 changes: 4 additions & 2 deletions src/ProChat/store/reducers/message.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ describe('messagesReducer', () => {
expect(newState.find((m) => m.id === 'message3')).toEqual({
id: 'message3',
content: 'New Message',
message: 'New Message',
createAt: expect.any(Number),
updateAt: expect.any(Number),
parentId: undefined,
role: 'user',
});
});
Expand All @@ -72,9 +72,9 @@ describe('messagesReducer', () => {
expect(newState.find((m) => m.id === 'customId')).toEqual({
id: 'customId',
content: 'New Message',
message: 'New Message',
createAt: expect.any(Number),
updateAt: expect.any(Number),
parentId: undefined,
role: 'user',
});
});
Expand All @@ -93,6 +93,7 @@ describe('messagesReducer', () => {
expect(newState.find((m) => m.id === 'message3')).toEqual({
id: 'message3',
content: 'New Message',
message: 'New Message',
createAt: expect.any(Number),
updateAt: expect.any(Number),
role: 'user',
Expand All @@ -114,6 +115,7 @@ describe('messagesReducer', () => {
expect(newState.find((m) => m.id === 'message3')).toEqual({
id: 'message3',
content: 'New Message',
message: 'New Message',
createAt: expect.any(Number),
updateAt: expect.any(Number),
role: 'user',
Expand Down

0 comments on commit 854432d

Please sign in to comment.