V
V
Vladimir2022-02-20 05:18:00
JavaScript
Vladimir, 2022-02-20 05:18:00

How to fix violetion took 200ms when scrolling a block with message loading?

Hello. I load messages by 20 pieces, update the state when it reaches 0 on scroll and twist the block 20 messages back. But after a few scrolls, the page freezes and I get a warning in the console:

[Violation] 'message' handler took 187ms


I tried e.preventDefault() - didn't work, e.stopPropagation() - similar.
Please tell me what I did wrong?

onScroll={(e) => {
                    if(e.target.scrollTop < 1) {
                        const msgID = prevMessages.length ? parseInt(prevMessages[0].id) : parseInt(messages[0].id);
                        console.log(msgID);
                        socket.emit('getPrevMessages', {roomId, msgID});
                        e.target.scrollTo(0, e.target.querySelector('.direct-chat-msg:nth-child(20)').offsetTop);
                        e.stopPropagation();
                    }
                }}


Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question