OvidijusParsiunas / deep-chat

Fully customizable AI chatbot component for your website
https://deepchat.dev
MIT License
1.27k stars 175 forks source link

Chat does not automatically scroll to the bottom on load #84

Closed OvidijusParsiunas closed 6 months ago

OvidijusParsiunas commented 6 months ago

Chat may not always automatically scroll to the very bottom on the initial render. This can happen when the chat is pre-populated with messages using initialMessages or introMessage.

Example code:

chatElementRef.initialMessages = [
    {text: 'asdasdasd'},
    {text: 'asdasdasd'},
    {text: 'asduasdiuhasdiuasdsa'},
    {text: 'asdiujasiuhdiuashduihasd'},
    {text: 'sadoijasiudasiudhsauidh'},
    {text: 'sadoijasiudasiudhsauidh'},
    {text: 'sadoijasiudasiudhsauidh'},
    {text: 'sadoijasiudasiudhsauidh'},
  ]

Result on initial render:

image
OvidijusParsiunas commented 6 months ago

Cause: Deep Chat uses the Inter, sans-serif, Avenir, Helvetica, Arial value for its default font-family property which it formats by adding the following head url to the DOM's header and download the font files: https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap

If the font files are downloaded later than the automatic initial scroll to the bottom is triggered, the formatted text size can have different dimensions, which in turn will change the chat height that is different to the scrolled dimensions.

How to prevent this: There are multiple ways to prevent this: