mirror of
https://github.com/bitwarden/browser
synced 2025-12-12 14:23:32 +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:
@@ -466,15 +466,24 @@ export class VaultV2Component<C extends CipherViewLike>
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const updatedCipher = await this.cipherService.get(
|
// The encrypted state of ciphers is updated when an attachment is added,
|
||||||
this.cipherId as CipherId,
|
// but the cache is also cleared. Depending on timing, `cipherService.get` can return the
|
||||||
this.activeUserId as UserId,
|
// old cipher. Retrieve the updated cipher from `cipherViews$`,
|
||||||
);
|
// which refreshes after the cached is cleared.
|
||||||
const updatedCipherView = await this.cipherService.decrypt(
|
const updatedCipherView = await firstValueFrom(
|
||||||
updatedCipher,
|
this.cipherService.cipherViews$(this.activeUserId!).pipe(
|
||||||
this.activeUserId as UserId,
|
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) => {
|
this.cipherFormComponent.patchCipher((currentCipher) => {
|
||||||
currentCipher.attachments = updatedCipherView.attachments;
|
currentCipher.attachments = updatedCipherView.attachments;
|
||||||
currentCipher.revisionDate = updatedCipherView.revisionDate;
|
currentCipher.revisionDate = updatedCipherView.revisionDate;
|
||||||
@@ -499,7 +508,6 @@ export class VaultV2Component<C extends CipherViewLike>
|
|||||||
|
|
||||||
if (cipher.decryptionFailure) {
|
if (cipher.decryptionFailure) {
|
||||||
invokeMenu(menu);
|
invokeMenu(menu);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cipher.isDeleted) {
|
if (!cipher.isDeleted) {
|
||||||
|
|||||||
Reference in New Issue
Block a user