Save project state before storing assets instead of after.

This commit is contained in:
Karishma Chadha committed 2019-01-07 17:14:51 -05:00
1 parent 69aa8c0946
commit 933bdd7c05
1 file changed
+8 -1
+8 -1
View File
@@ -201,6 +201,13 @@ const ProjectSaverHOC = function (WrappedComponent) {
storeProject (projectId, requestParams) {
requestParams = requestParams || {};
this.clearAutoSaveTimeout();
// Serialize VM state now before embarking on
// the asynchronous journey of storing assets to
// the server. This ensures that assets don't update
// while in the process of saving a project (e.g. the
// serialized project refers to a newer asset than what
// we just finished saving).
const savedVMState = this.props.vm.toJSON();
return Promise.all(this.props.vm.assets
.filter(asset => !asset.clean)
.map(
@@ -215,7 +222,7 @@ const ProjectSaverHOC = function (WrappedComponent) {
)
).then(() => {
const opts = {
body: this.props.vm.toJSON(),
body: savedVMState,
// If we set json:true then the body is double-stringified, so don't
headers: {
'Content-Type': 'application/json'