-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix stale data issue in new login popout #17307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
1de8d92
0357842
43b3eb2
2c43bb3
b109bfa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| // FIXME: Update this file to be type safe and remove this and next line | ||
| // @ts-strict-ignore | ||
| import { CommonModule } from "@angular/common"; | ||
| import { Component, OnInit } from "@angular/core"; | ||
| import { Component, OnInit, OnDestroy } from "@angular/core"; | ||
| import { takeUntilDestroyed } from "@angular/core/rxjs-interop"; | ||
| import { FormsModule } from "@angular/forms"; | ||
| import { ActivatedRoute, Params, Router } from "@angular/router"; | ||
|
|
@@ -158,7 +158,7 @@ export type AddEditQueryParams = Partial<Record<keyof QueryParams, string>>; | |
| IconButtonModule, | ||
| ], | ||
| }) | ||
| export class AddEditV2Component implements OnInit { | ||
| export class AddEditV2Component implements OnInit, OnDestroy { | ||
| headerText: string; | ||
| config: CipherFormConfig; | ||
| canDeleteCipher$: Observable<boolean>; | ||
|
|
@@ -200,12 +200,56 @@ export class AddEditV2Component implements OnInit { | |
| this.subscribeToParams(); | ||
| } | ||
|
|
||
| private messageListener: (message: any) => void; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The Suggested fixDefine a message type interface: interface ReloadCipherDataMessage {
command: string;
data?: {
cipherId?: string;
cipherType?: CipherType;
};
}
private messageListener: (message: ReloadCipherDataMessage) => void; |
||
|
|
||
| async ngOnInit() { | ||
| this.fido2PopoutSessionData = await firstValueFrom(this.fido2PopoutSessionData$); | ||
|
|
||
| if (BrowserPopupUtils.inPopout(window)) { | ||
| this.popupCloseWarningService.enable(); | ||
| } | ||
|
|
||
| // Listen for messages to reload cipher data when the pop up is already open | ||
| this.messageListener = async (message: any) => { | ||
| if (message?.command === "reloadAddEditCipherData") { | ||
| await this.reloadCipherData(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If Suggested fixAdd try-catch to handle errors gracefully: this.messageListener = async (message: any) => {
if (message?.command === "reloadAddEditCipherData") {
try {
await this.reloadCipherData();
} catch (error) {
this.logService.error("Failed to reload cipher data", error);
}
}
}; |
||
| } | ||
| }; | ||
| BrowserApi.addListener(chrome.runtime.onMessage, this.messageListener); | ||
| } | ||
|
|
||
| ngOnDestroy() { | ||
| if (this.messageListener) { | ||
| chrome.runtime.onMessage.removeListener(this.messageListener); | ||
| } | ||
jholland-livefront marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /** | ||
| * Reloads the cipher data when the popup is already open and new form data is submitted. | ||
| */ | ||
| private async reloadCipherData() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. โป๏ธ Finding 4: Missing comprehensive test coverage for Codecov reports 56.52% patch coverage with 10 lines missing coverage. The Recommended test cases:
|
||
| if (!this.config) { | ||
| return; | ||
| } | ||
|
|
||
| const activeUserId = await firstValueFrom(this.accountService.activeAccount$.pipe(getUserId)); | ||
|
|
||
| const latestCipherInfo = await firstValueFrom( | ||
| this.cipherService.addEditCipherInfo$(activeUserId), | ||
| ); | ||
|
|
||
| if (latestCipherInfo != null) { | ||
| this.config = { | ||
| ...this.config, | ||
| initialValues: { | ||
| ...this.config.initialValues, | ||
| ...mapAddEditCipherInfoToInitialValues(latestCipherInfo), | ||
| }, | ||
| }; | ||
|
|
||
| // Be sure to clear the "cached" cipher info, so it doesn't get used again | ||
| await this.cipherService.setAddEditCipherInfo(null, activeUserId); | ||
| } | ||
| } | ||
|
Comment on lines
231
to
251
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. โป๏ธ Finding 4: Missing test coverage for Codecov reports 56.52% patch coverage with 10 lines missing coverage. The Recommended test cases:
|
||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,6 +97,11 @@ async function openAddEditVaultItemPopout( | |
| let singleActionKey = VaultPopoutType.addEditVaultItem; | ||
| let addEditCipherUrl = "popup/index.html#/edit-cipher"; | ||
| let queryParamToken = "?"; | ||
| const extensionUrl = chrome.runtime.getURL("popup/index.html"); | ||
| const existingPopupTabs = await BrowserApi.tabsQuery({ url: `${extensionUrl}*` }); | ||
| const existingPopup = existingPopupTabs.find((tab) => | ||
| tab.url?.includes(`singleActionPopout=${singleActionKey}`), | ||
| ); | ||
| const formatQueryString = (key: string, value: string) => { | ||
| const queryString = `${queryParamToken}${key}=${value}`; | ||
| queryParamToken = "&"; | ||
jholland-livefront marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
@@ -115,10 +120,21 @@ async function openAddEditVaultItemPopout( | |
| addEditCipherUrl += formatQueryString("uri", url); | ||
| } | ||
|
|
||
| await BrowserPopupUtils.openPopout(addEditCipherUrl, { | ||
| singleActionKey, | ||
| senderWindowId: windowId, | ||
| }); | ||
| // Check if the an existing popup is already open | ||
| if (existingPopup) { | ||
| await chrome.runtime.sendMessage({ | ||
| command: "reloadAddEditCipherData", | ||
| data: { cipherId, cipherType }, | ||
| }); | ||
|
Comment on lines
+125
to
+128
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๐ญ Finding 5: No error handling for message sending If Consider adding try-catch and logging: try {
await chrome.runtime.sendMessage({
command: "reloadAddEditCipherData",
data: { cipherId, cipherType },
});
await BrowserApi.updateWindowProperties(existingPopup.windowId, {
focused: true,
});
} catch (error) {
// Log error and fall back to opening a new popout
console.error("Failed to send reload message, opening new popout", error);
await BrowserPopupUtils.openPopout(addEditCipherUrl, {
singleActionKey,
senderWindowId: windowId,
});
}There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๐ญ Finding 5: No error handling for message sending If Consider adding try-catch and logging: try {
await chrome.runtime.sendMessage({
command: "reloadAddEditCipherData",
data: { cipherId, cipherType },
});
await BrowserApi.updateWindowProperties(existingPopup.windowId, {
focused: true,
});
} catch (error) {
// Log error and fall back to opening a new popout
console.error("Failed to send reload message, opening new popout", error);
await BrowserPopupUtils.openPopout(addEditCipherUrl, {
singleActionKey,
senderWindowId: windowId,
});
} |
||
| await BrowserApi.updateWindowProperties(existingPopup.windowId, { | ||
| focused: true, | ||
| }); | ||
| } else { | ||
| await BrowserPopupUtils.openPopout(addEditCipherUrl, { | ||
| singleActionKey, | ||
| senderWindowId: windowId, | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
anytypeThe
messageListenerparameter is typed asany, which bypasses type safety and could lead to runtime errors if the message structure changes.Suggested fix
Define a message type interface: