From 0c01cf69b8dd6ee9c0d07868fc51bc8f3352e4dc Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Sat, 16 Sep 2023 13:28:49 +0400 Subject: [PATCH] Wait for the counter update during the load. Fixes #5385 --- src/editor/model/Editor.ts | 4 +++- src/utils/mixins.ts | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/editor/model/Editor.ts b/src/editor/model/Editor.ts index 3fb12e22f..90d6a0fa9 100644 --- a/src/editor/model/Editor.ts +++ b/src/editor/model/Editor.ts @@ -2,7 +2,7 @@ import { isUndefined, isArray, contains, toArray, keys, bindAll } from 'undersco import Backbone from 'backbone'; import $ from '../../utils/cash-dom'; import Extender from '../../utils/extender'; -import { getModel, hasWin, isEmptyObj } from '../../utils/mixins'; +import { getModel, hasWin, isEmptyObj, wait } from '../../utils/mixins'; import { AddOptions, Model } from '../../common'; import Selected from './Selected'; import FrameView from '../../canvas/view/FrameView'; @@ -835,6 +835,8 @@ export default class EditorModel extends Model { async load(options?: any) { const result = await this.Storage.load(options); this.loadData(result); + // Wait in order to properly update the dirty counter (#5385) + await wait(); return result; } diff --git a/src/utils/mixins.ts b/src/utils/mixins.ts index 0b75b6bbf..da205a310 100644 --- a/src/utils/mixins.ts +++ b/src/utils/mixins.ts @@ -5,6 +5,8 @@ import { isTextNode } from './dom'; import Component from '../dom_components/model/Component'; import { ObjectAny } from '../common'; +export const wait = (mls: number = 0) => new Promise(res => setTimeout(res, mls)); + export const isDef = (value: any) => typeof value !== 'undefined'; export const hasWin = () => typeof window !== 'undefined';