Browse Source

Merge branch 'dev' of https://github.com/GrapesJS/grapesjs into pages-datasources

pages-datasources
mohamedsalem401 1 year ago
parent
commit
efd75e32dc
  1. 13
      packages/core/src/editor/model/Editor.ts

13
packages/core/src/editor/model/Editor.ts

@ -119,6 +119,7 @@ export default class EditorModel extends Model {
destroyed = false; destroyed = false;
_config: InitEditorConfig; _config: InitEditorConfig;
_storageTimeout?: ReturnType<typeof setTimeout>; _storageTimeout?: ReturnType<typeof setTimeout>;
_isStoring: boolean = false;
attrsOrig: any; attrsOrig: any;
timedInterval?: ReturnType<typeof setTimeout>; timedInterval?: ReturnType<typeof setTimeout>;
updateItr?: ReturnType<typeof setTimeout>; updateItr?: ReturnType<typeof setTimeout>;
@ -869,9 +870,19 @@ export default class EditorModel extends Model {
* @public * @public
*/ */
async store<T extends StorageOptions>(options?: T) { async store<T extends StorageOptions>(options?: T) {
if (this._isStoring) return;
this._isStoring = true;
// We use a 1ms timeout to defer the cleanup to the next tick of the event loop.
// This prevents a race condition where a store operation, like 'sync:content',
// might increase the dirty count before it can be properly cleared.
setTimeout(() => {
this.clearDirtyCount();
}, 1);
const data = this.storeData(); const data = this.storeData();
await this.Storage.store(data, options); await this.Storage.store(data, options);
this.clearDirtyCount(); setTimeout(() => {
this._isStoring = false;
}, 1);
return data; return data;
} }

Loading…
Cancel
Save