graph-update: batch updates in reducer
Prevents strange state desynchronisation in child components,
specifically sending a chat message no longer sometimes appears as
deleted.
Fixes urbit/landscape#953
@@ -9,6 +9,9 @@ import produce from 'immer';
import _ from 'lodash';
import { BaseState, reduceState } from '../state/base';
import useGraphState, { GraphState as State } from '../state/graph';
+/* eslint-disable camelcase */
+
+import { unstable_batchedUpdates } from 'react-dom';
type GraphState = State & BaseState<State>;
@@ -456,6 +459,7 @@ export const reduceDm = [
export const GraphReducer = (json) => {
const data = _.get(json, 'graph-update', false);
+ unstable_batchedUpdates(() => {
if (data) {
reduceState<GraphState, any>(useGraphState, data, [
keys,
@@ -479,4 +483,5 @@ export const GraphReducer = (json) => {
if (thread) {
reduceState<GraphState, any>(useGraphState, thread, [addNodesThread]);
}
+ });
};
