react-native-gifted-chat icon indicating copy to clipboard operation
react-native-gifted-chat copied to clipboard

Gifted chat is sometimes not rendered on the Web version (HOWTO / Solution)

Open l2aelba opened this issue 2 years ago • 10 comments

Just for someone who is looking for this.

Sometimes you have already loaded the messages and the user is navigating quickly.

Users will get ⚠️ empty / blank screen ⚠️ (I don't know why)

I made a JS can you can use for re-render the gifted chat (HACK solution)

if (Platform.OS === 'web') {
  const gcLoadingContaineEl = document.querySelectorAll('[data-testid="GC_LOADING_CONTAINER"]')[0] as HTMLElement
  if (gcLoadingContaineEl) {
    gcLoadingContaineEl.style.display = 'none'
    setTimeout(() => {
      gcLoadingContaineEl.style.display = 'flex'
    }, 500)
  }
}

// Add this somewhere in your code, for example when fetching messages or `useEffect` with 10 secs delayed

This script will let the gifted render it again if GC_LOADING_CONTAINER found

l2aelba avatar Oct 09 '23 10:10 l2aelba

very helpful thank you

jacksonwalker165 avatar Oct 19 '23 06:10 jacksonwalker165

Facing the exact same issue, thanks 🙏

Rafaa17 avatar Oct 19 '23 06:10 Rafaa17

faced the same issue gifted chat render blank page on chrome :(

quocvuong2000 avatar Oct 23 '23 16:10 quocvuong2000

This was very helpful

maaizelahi avatar Nov 20 '23 11:11 maaizelahi

@FaridSafi take a look when you have time. thanks.

l2aelba avatar Nov 21 '23 12:11 l2aelba

Thank you, this resolves a critical issue for us. I am seeing this same issue for a high % of views when we are using react native web, but the browser is a native webview in an iOS app.

In a regular desktop web browser, more commonly we are seeing the Composer and Load More button render just fine, but the messages are not rendering. Is this a related issue?

trevoriancox avatar Mar 25 '24 18:03 trevoriancox

import type { IMessage } from 'react-native-gifted-chat';
import { GiftedChat } from 'react-native-gifted-chat';

const EXISTING_CHATS:IMessage[] = [{
    _id: 'some-id',
    text: 'I load and you can read me',
    createdAt: new Date(),
    user: {
       _id: 'another-user-id'
    }
  }]

export function ChatRoom({ id }: { id: string }) {
  const [messages, setMessages] = useState(EXISTING_CHATS);
  const onSend = useCallback((messages: IMessage[] = []) => {
    setMessages((previousMessages) =>
      GiftedChat.append(previousMessages, messages),
    );
  }, []);
  useEffect(() => {
    invisibleMessagesLoadingFix();
  });
  return (
        <GiftedChat
          messages={messages}
          onSend={(messages) => onSend(messages)}
          user={{ _id: `active-user-id }}
        />
  );
}

function invisibleMessagesLoadingFix() {
  if (Platform.OS === 'web') {
    const gcLoadingContaineEl = document.querySelectorAll(
      '[data-testid="GC_LOADING_CONTAINER"]',
    )[0] as HTMLElement;
    if (gcLoadingContaineEl) {
      gcLoadingContaineEl.style.display = 'none';
      setTimeout(() => {
        gcLoadingContaineEl.style.display = 'flex';
      }, 500);
    }
  }
}

Here is a minimal implementation of the above fix in typescript

the-simian avatar Jun 14 '24 01:06 the-simian

Facing the same issue.

xuelink avatar Jul 07 '24 09:07 xuelink