1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-11 05:43:41 +00:00

get updated cipher from cipherViews$ on desktop. This avoids a race condition with waiting for the new cipher to be upserted in some cases. (#15859)

This commit is contained in:
Nick Krantz
2025-08-05 08:38:45 -05:00
committed by GitHub
parent 80b74b3300
commit 920145b393

View File

@@ -466,15 +466,24 @@ export class VaultV2Component<C extends CipherViewLike>
return;
}
const updatedCipher = await this.cipherService.get(
this.cipherId as CipherId,
this.activeUserId as UserId,
);
const updatedCipherView = await this.cipherService.decrypt(
updatedCipher,
this.activeUserId as UserId,
// The encrypted state of ciphers is updated when an attachment is added,
// but the cache is also cleared. Depending on timing, `cipherService.get` can return the
// old cipher. Retrieve the updated cipher from `cipherViews$`,
// which refreshes after the cached is cleared.
const updatedCipherView = await firstValueFrom(
this.cipherService.cipherViews$(this.activeUserId!).pipe(
filter((c) => !!c),
map((ciphers) => ciphers.find((c) => c.id === this.cipherId)),
),
);
// `find` can return undefined but that shouldn't happen as
// this would mean that the cipher was deleted.
// To make TypeScript happy, exit early if it isn't found.
if (!updatedCipherView) {
return;
}
this.cipherFormComponent.patchCipher((currentCipher) => {
currentCipher.attachments = updatedCipherView.attachments;
currentCipher.revisionDate = updatedCipherView.revisionDate;
@@ -499,7 +508,6 @@ export class VaultV2Component<C extends CipherViewLike>
if (cipher.decryptionFailure) {
invokeMenu(menu);
return;
}
if (!cipher.isDeleted) {