diff --git a/src/services/new/workbook/copy-workbook.ts b/src/services/new/workbook/copy-workbook.ts index dccb991c..a71c44f8 100644 --- a/src/services/new/workbook/copy-workbook.ts +++ b/src/services/new/workbook/copy-workbook.ts @@ -351,13 +351,18 @@ export async function crossSyncCopiedJoinedEntryRevisions({ newByOldEntryIdMap.set(encodedTargetConnectionId, encodedTemplateConnectionId); } + await Utils.waitNextMacrotask(); let strCopiedJoinedEntryRevisions = JSON.stringify(arCopiedJoinedEntryRevisions); - newByOldEntryIdMap.forEach((value, key) => { + + for (const [key, value] of newByOldEntryIdMap) { + await Utils.waitNextMacrotask(); strCopiedJoinedEntryRevisions = strCopiedJoinedEntryRevisions.replace( new RegExp(value, 'g'), key, ); - }); + } + + await Utils.waitNextMacrotask(); const arCopiedJoinedEntryRevisionsWithReplacedIds = JSON.parse( strCopiedJoinedEntryRevisions, ) as JoinedEntryRevisionColumns[]; diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 243fef43..e3f8ac81 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -172,6 +172,12 @@ export class Utils { return results; } + static waitNextMacrotask = async () => { + return new Promise((resolve) => { + setImmediate(resolve); + }); + }; + static encodeId(bigIntId: any) { let encodedId = '';