Fix history initialization (#2115)

This commit is contained in:
David Luzar 2020-09-09 21:08:06 +02:00 committed by GitHub
parent 9cac7816cc
commit aaddde5dd9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 1052 additions and 48 deletions

View file

@ -556,7 +556,11 @@ class App extends React.Component<ExcalidrawProps, AppState> {
),
};
}
this.syncActionResult(scene);
history.clear();
this.syncActionResult({
...scene,
commitToHistory: true,
});
}
};
@ -1163,11 +1167,12 @@ class App extends React.Component<ExcalidrawProps, AppState> {
const updateScene = (
decryptedData: SocketUpdateDataSource[SCENE.INIT | SCENE.UPDATE],
{ scrollToContent = false }: { scrollToContent?: boolean } = {},
{ init = false }: { init?: boolean } = {},
) => {
const { elements: remoteElements } = decryptedData.payload;
if (scrollToContent) {
if (init) {
history.resumeRecording();
this.setState({
...this.state,
...calculateScrollCenter(
@ -1292,7 +1297,7 @@ class App extends React.Component<ExcalidrawProps, AppState> {
return;
case SCENE.INIT: {
if (!this.portal.socketInitialized) {
updateScene(decryptedData, { scrollToContent: true });
updateScene(decryptedData, { init: true });
}
break;
}
@ -3626,7 +3631,7 @@ class App extends React.Component<ExcalidrawProps, AppState> {
...(appState || this.state),
isLoading: false,
},
commitToHistory: false,
commitToHistory: true,
}),
)
.catch((error) => {