From 0dc07135b743fd0a9610b73b73d7e363fdb367d1 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Mon, 16 Mar 2020 19:21:01 -0700 Subject: [PATCH] Fix three rendering when loading (#986) The problem is that syncActionResult wasn't using batching. --- src/components/App.tsx | 43 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/src/components/App.tsx b/src/components/App.tsx index 0f84ba29..860c1b65 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -186,31 +186,30 @@ export class App extends React.Component { this.actionManager.registerAction(createRedoAction(history)); } - private syncActionResult = ( - res: ActionResult, - commitToHistory: boolean = true, - ) => { - if (this.unmounted) { - return; - } - if (res.elements) { - globalSceneState.replaceAllElements(res.elements); - if (commitToHistory) { - history.resumeRecording(); + private syncActionResult = withBatchedUpdates( + (res: ActionResult, commitToHistory: boolean = true) => { + if (this.unmounted) { + return; + } + if (res.elements) { + globalSceneState.replaceAllElements(res.elements); + if (commitToHistory) { + history.resumeRecording(); + } } - } - if (res.appState) { - if (commitToHistory) { - history.resumeRecording(); + if (res.appState) { + if (commitToHistory) { + history.resumeRecording(); + } + this.setState(state => ({ + ...res.appState, + isCollaborating: state.isCollaborating, + collaborators: state.collaborators, + })); } - this.setState(state => ({ - ...res.appState, - isCollaborating: state.isCollaborating, - collaborators: state.collaborators, - })); - } - }; + }, + ); private onCut = withBatchedUpdates((event: ClipboardEvent) => { if (isWritableElement(event.target)) {