From b5d865e8f275e9ccefff97d77c494fdbbfd51405 Mon Sep 17 00:00:00 2001 From: Nick Krantz <125900171+nick-livefront@users.noreply.github.com> Date: Thu, 5 Feb 2026 13:42:50 -0600 Subject: [PATCH] move `clearCache` before `updateWithServer` (#18790) --- libs/common/src/vault/services/cipher.service.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/libs/common/src/vault/services/cipher.service.ts b/libs/common/src/vault/services/cipher.service.ts index 523a6490fb8..6373a511724 100644 --- a/libs/common/src/vault/services/cipher.service.ts +++ b/libs/common/src/vault/services/cipher.service.ts @@ -934,12 +934,17 @@ export class CipherService implements CipherServiceAbstraction { userId: UserId, orgAdmin?: boolean, ): Promise { + // Clear the cache before creating the cipher. The SDK internally updates the encrypted storage + // but the timing of the storage emitting the new values differs across platforms. Clearing the cache after + // `createWithServer` can cause race conditions where the cache is cleared after the + // encrypted storage has already been updated and thus downstream consumers not getting updated data. + await this.clearCache(userId); + const resultCipherView = await this.cipherSdkService.createWithServer( cipherView, userId, orgAdmin, ); - await this.clearCache(userId); return resultCipherView; } @@ -993,13 +998,18 @@ export class CipherService implements CipherServiceAbstraction { originalCipherView?: CipherView, orgAdmin?: boolean, ): Promise { + // Clear the cache before updating the cipher. The SDK internally updates the encrypted storage + // but the timing of the storage emitting the new values differs across platforms. Clearing the cache after + // `updateWithServer` can cause race conditions where the cache is cleared after the + // encrypted storage has already been updated and thus downstream consumers not getting updated data. + await this.clearCache(userId); + const resultCipherView = await this.cipherSdkService.updateWithServer( cipher, userId, originalCipherView, orgAdmin, ); - await this.clearCache(userId); return resultCipherView; }