Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: infinite render and console errors due to search component #503

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions packages/react/src/components/SearchMessage/SearchMessage.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import React, { useState, useContext, useMemo, useEffect } from 'react';
import React, { useState, useContext, useEffect } from 'react';
import { isSameDay, format } from 'date-fns';
import { debounce } from 'lodash';
import RCContext from '../../context/RCInstance';
import classes from './SearchMessage.module.css';
import { useUserStore, useSearchMessageStore } from '../../store';
import { useSearchMessageStore } from '../../store';
import { Box } from '../Box';
import { Icon } from '../Icon';
import { ActionButton } from '../ActionButton';
import { MessageDivider } from '../Message/MessageDivider';
import { Message } from '../Message';
import isMessageSequential from '../../lib/isMessageSequential';

const Search = () => {
const { RCInstance } = useContext(RCContext);
Expand Down Expand Up @@ -37,7 +36,9 @@ const Search = () => {

useEffect(() => {
if (!text.trim()) {
setMessageList([]);
if (messageList.length > 0) {
setMessageList([]);
}
} else {
debouncedSearch();
}
Expand All @@ -46,7 +47,7 @@ const Search = () => {
return () => {
debouncedSearch.cancel();
};
}, [text, debouncedSearch]);
}, [text, debouncedSearch, messageList.length]);

const isMessageNewDay = (current, previous) =>
!previous || !isSameDay(new Date(current.ts), new Date(previous.ts));
Expand All @@ -69,7 +70,7 @@ const Search = () => {
Search Messages
</Box>
<ActionButton onClick={toggleShowSearch} ghost size="small">
<Icon name="cross" size="x20" />
<Icon name="cross" />
</ActionButton>
</h3>
</Box>
Expand Down Expand Up @@ -125,7 +126,6 @@ const Search = () => {
messageList.map((msg, index, arr) => {
const prev = arr[index + 1];
const newDay = isMessageNewDay(msg, prev);
const sequential = isMessageSequential(msg, prev, 300);
return (
<Box key={msg._id}>
{newDay && (
Expand Down
Loading