fix: scene not initialized properly when tab not focused (#2677)

Co-authored-by: Lipis <lipiridis@gmail.com>
This commit is contained in:
David Luzar 2020-12-29 21:03:34 +01:00 committed by GitHub
parent 0cf58adb4c
commit aef3644c93
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 16 deletions

View file

@ -861,7 +861,16 @@ class App extends React.Component<ExcalidrawProps, AppState> {
history.record(this.state, this.scene.getElementsIncludingDeleted());
this.props.onChange?.(this.scene.getElementsIncludingDeleted(), this.state);
// Do not notify consumers if we're still loading the scene. Among other
// potential issues, this fixes a case where the tab isn't focused during
// init, which would trigger onChange with empty elements, which would then
// override whatever is in localStorage currently.
if (!this.state.isLoading) {
this.props.onChange?.(
this.scene.getElementsIncludingDeleted(),
this.state,
);
}
}
// Copy/paste