Use react-redux's batch instead of react's

This commit is contained in:
Fedor Indutny 2021-11-01 16:38:08 -07:00 committed by GitHub
parent 3190f95fac
commit 663cd77eac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 123 additions and 66 deletions

View file

@ -4,7 +4,8 @@
import { webFrame } from 'electron';
import { isNumber, noop } from 'lodash';
import { bindActionCreators } from 'redux';
import { render, unstable_batchedUpdates as batchedUpdates } from 'react-dom';
import { render } from 'react-dom';
import { batch as batchDispatch } from 'react-redux';
import MessageReceiver from './textsecure/MessageReceiver';
import type {
@ -1043,7 +1044,7 @@ export async function startApp(): Promise<void> {
`${batch.length} into ${deduped.size}`
);
batchedUpdates(() => {
batchDispatch(() => {
deduped.forEach(conversation => {
conversationChanged(conversation.id, conversation.format());
});
@ -1058,11 +1059,21 @@ export async function startApp(): Promise<void> {
maxSize: Infinity,
});
convoCollection.on('props-change', conversation => {
convoCollection.on('props-change', (conversation, isBatched) => {
if (!conversation) {
return;
}
// `isBatched` is true when the `.set()` call on the conversation model
// already runs from within `react-redux`'s batch. Instead of batching
// the redux update for later - clear all queued updates and update
// immediately.
if (isBatched) {
changedConvoBatcher.removeAll(conversation);
conversationChanged(conversation.id, conversation.format());
return;
}
changedConvoBatcher.add(conversation);
});
convoCollection.on('reset', removeAllConversations);