From 6e190b9703b79e7ebddd96d39c61fa076cf544bd Mon Sep 17 00:00:00 2001 From: EYHN Date: Wed, 28 May 2025 14:40:31 +0000 Subject: [PATCH] fix(core): migrate collection info before update it (#12617) ## Summary by CodeRabbit - **Bug Fixes** - Improved reliability when updating collection information, ensuring data is correctly migrated and validated before saving changes. This prevents issues with incomplete or invalid collection data. --- .../core/src/modules/collection/stores/collection.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/frontend/core/src/modules/collection/stores/collection.ts b/packages/frontend/core/src/modules/collection/stores/collection.ts index 622ef4f9ca..58277c90bc 100644 --- a/packages/frontend/core/src/modules/collection/stores/collection.ts +++ b/packages/frontend/core/src/modules/collection/stores/collection.ts @@ -164,12 +164,13 @@ export class CollectionStore extends Store { if (collection.id === id) { this.rootYDoc.transact(() => { yArray.delete(collectionIndex, 1); + const migratedCollectionInfo = this.migrateCollectionInfo(collection); yArray.insert(collectionIndex, [ { id: collection.id, - name: info.name ?? collection.name, - rules: info.rules ?? collection.rules, - allowList: info.allowList ?? collection.allowList, + name: info.name ?? migratedCollectionInfo.name, + rules: info.rules ?? migratedCollectionInfo.rules, + allowList: info.allowList ?? migratedCollectionInfo.allowList, }, ]); }); @@ -183,7 +184,7 @@ export class CollectionStore extends Store { migrateCollectionInfo( legacyCollectionInfo: LegacyCollectionInfo ): CollectionInfo { - if ('rules' in legacyCollectionInfo) { + if ('rules' in legacyCollectionInfo && legacyCollectionInfo.rules) { return legacyCollectionInfo as CollectionInfo; } return {