Answer the question
In order to leave comments, you need to log in
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
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();
}
}}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question