WEB-968: Memory leaks, bugs and build hygiene#3618
Conversation
|
Note
|
| Layer / File(s) | Summary |
|---|---|
Angular build and npm configuration angular.json, package.json |
Cypress architect targets removed from angular.json; Cypress scripts (e2e, cypress:open, cypress:run), Cypress and schematic dependencies, and unused packages (basic-ftp, hono, tar) removed from package.json. |
Cypress infrastructure and configuration files cypress/tsconfig.json, cypress/plugins/index.ts, cypress/support/commands.ts, cypress/support/e2e.ts, e2e/.eslintrc.json, e2e/cypress.json, e2e/cypress/plugins/index.ts, e2e/cypress/support/commands.ts, e2e/cypress/support/index.ts, e2e/cypress/tsconfig.json, e2e/tsconfig.e2e.json, e2e/tsconfig.json |
All Cypress framework configuration, plugin handlers, support setup, TypeScript compiler overrides, and ESLint rules deleted from both cypress/ and e2e/ directories. |
Cypress E2E test files cypress/e2e/audit-trails.cy.ts, cypress/e2e/spec.cy.ts |
Login page and audit trails E2E test suites removed. |
testRigor test automation framework e2e/testRigor/README.md, e2e/testRigor/run_testrigor_tests.sh, e2e/testRigor/rules/*, e2e/testRigor/testcases/* |
Entire testRigor test automation framework removed, including documentation, bash runner script, and all rule and test case files for authentication, client/account/organization/user management, and accounting workflows. |
RxJS Lifecycle Management and Component Improvements
| Layer / File(s) | Summary |
|---|---|
Component subscription lifecycle management via DestroyRef src/app/accounting/provisioning-entries/view-provisioning-entry/view-provisioning-entry.component.ts, src/app/accounting/search-journal-entry/search-journal-entry.component.ts, src/app/centers/centers.component.ts, src/app/groups/groups.component.ts, src/app/system/audit-trails/audit-trails.component.ts |
Five components now inject Angular's DestroyRef and apply takeUntilDestroyed(this.destroyRef) to form control valueChanges observables and table sort/pagination streams to automatically unsubscribe on component destruction, preventing memory leaks. |
Service, component detection, and environment improvements src/app/loans/loans.service.ts, src/app/products/share-products/dividends-share-product/dividends.components.ts, src/environments/environment.ts |
LoansService.getLoanDisbursementDetailsData() now uses nullish coalescing to ensure JSON.parse receives a non-null string; ShareProductsDividendsComponent enables OnPush change detection strategy; environment.preloadClients now uses !== false logic to preserve explicit false values instead of always defaulting to true. |
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~60 minutes
Possibly related PRs
- openMF/web-app#3463: Updates Docker build configuration to skip Cypress installation (
CYPRESS_INSTALL_BINARY=0) while preparing infrastructure for Playwright-based E2E testing, complementing this PR's removal of Cypress from the codebase.
Suggested reviewers
- IOhacker
- adamsaghy
- gkbishnoi07
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title accurately summarizes the main changes: memory leaks, bugs, and build hygiene improvements, which aligns with the comprehensive technical cleanup including subscriptions management, dependency removal, and E2E testing consolidation. |
| Docstring Coverage | ✅ Passed | No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. |
| Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create PR with unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/environments/environment.ts (1)
65-65: ⚡ Quick winConsider checking for string
'false'to match other environment flag patterns.The fix correctly preserves boolean
false, but other environment flags in this file check for both string'false'and booleanfalse(see lines 91, 98). Ifwindow.env['preloadClients']could be the string'false', it will be treated as truthy with the current logic.♻️ Proposed fix to match established pattern
- preloadClients: loadedEnv['preloadClients'] !== false, + preloadClients: loadedEnv['preloadClients'] !== 'false' && loadedEnv['preloadClients'] !== false,This aligns with the defensive pattern used for
mifosInterbankTransfersEnabled(line 91) andmifosRemittanceEnabled(line 98).🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/environments/environment.ts` at line 65, The preloadClients assignment currently only checks for boolean false; update the check on loadedEnv['preloadClients'] so it treats the string 'false' the same as boolean false (consistent with how mifosInterbankTransfersEnabled and mifosRemittanceEnabled are handled): ensure the expression excludes both 'false' (string) and false (boolean) when setting the preloadClients property.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/app/loans/loans.service.ts`:
- Around line 827-829: getLoanDisbursementDetailsData currently parses
localStorage.getItem('disbursementData') which can yield null
(JSON.parse('null') -> null) but the method signature expects
DisbursementData[]; change the method to check the stored value and return an
empty array when missing or parsed result is null/invalid. Locate
getLoanDisbursementDetailsData and implement a guard that reads the raw string,
returns [] if raw is null/empty, otherwise JSON.parse and validate/cast to
DisbursementData[] (or default to []) before returning so callers always receive
an array.
In
`@src/app/products/share-products/dividends-share-product/dividends.components.ts`:
- Line 10: The component uses ChangeDetectionStrategy.OnPush but mutates
this.dividendData inside the route subscription in DividendsComponent so the
view won't update; inject ChangeDetectorRef (via constructor or inject()) into
the component and after you update dividendData in the route subscription call
cdr.markForCheck() (or cdr.detectChanges()) to trigger change detection;
alternatively refactor dividendData to an Observable and expose it to the
template via async pipe instead of imperative mutation.
---
Nitpick comments:
In `@src/environments/environment.ts`:
- Line 65: The preloadClients assignment currently only checks for boolean
false; update the check on loadedEnv['preloadClients'] so it treats the string
'false' the same as boolean false (consistent with how
mifosInterbankTransfersEnabled and mifosRemittanceEnabled are handled): ensure
the expression excludes both 'false' (string) and false (boolean) when setting
the preloadClients property.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: df7307e1-40e6-4a22-a5a7-969bd1153c07
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.jsonand included by**/*
📒 Files selected for processing (54)
angular.jsoncypress/e2e/audit-trails.cy.tscypress/e2e/spec.cy.tscypress/plugins/index.tscypress/support/commands.tscypress/support/e2e.tscypress/tsconfig.jsone2e/.eslintrc.jsone2e/cypress.jsone2e/cypress/plugins/index.tse2e/cypress/support/commands.tse2e/cypress/support/index.tse2e/cypress/tsconfig.jsone2e/testRigor/README.mde2e/testRigor/rules/close-popup.txte2e/testRigor/rules/create-account.txte2e/testRigor/rules/create-admin-user.txte2e/testRigor/rules/create-client.txte2e/testRigor/rules/create-organization.txte2e/testRigor/rules/delete-admin-user.txte2e/testRigor/rules/delete-client.txte2e/testRigor/rules/log-in-and-validate.txte2e/testRigor/rules/logout.txte2e/testRigor/rules/navigate-to-accounting-creation.txte2e/testRigor/rules/navigate-to-admin-users-management.txte2e/testRigor/rules/navigate-to-clients.txte2e/testRigor/rules/navigate-to-offices.txte2e/testRigor/rules/pick-birthdate.txte2e/testRigor/rules/pick-today-date.txte2e/testRigor/rules/validate-login-page.txte2e/testRigor/run_testrigor_tests.she2e/testRigor/testcases/create-account.txte2e/testRigor/testcases/create-admin-user.txte2e/testRigor/testcases/create-client.txte2e/testRigor/testcases/create-journal-entries.txte2e/testRigor/testcases/create-new-office.txte2e/testRigor/testcases/delete-admin-user.txte2e/testRigor/testcases/delete-client.txte2e/testRigor/testcases/edit-mandatory-fields-of-organization.txte2e/testRigor/testcases/edit-organization.txte2e/testRigor/testcases/invalid-login.txte2e/testRigor/testcases/login.txte2e/testRigor/testcases/logout.txte2e/tsconfig.e2e.jsone2e/tsconfig.jsonpackage.jsonsrc/app/accounting/provisioning-entries/view-provisioning-entry/view-provisioning-entry.component.tssrc/app/accounting/search-journal-entry/search-journal-entry.component.tssrc/app/centers/centers.component.tssrc/app/groups/groups.component.tssrc/app/loans/loans.service.tssrc/app/products/share-products/dividends-share-product/dividends.components.tssrc/app/system/audit-trails/audit-trails.component.tssrc/environments/environment.ts
💤 Files with no reviewable changes (46)
- e2e/testRigor/rules/navigate-to-accounting-creation.txt
- e2e/testRigor/testcases/create-admin-user.txt
- e2e/testRigor/rules/navigate-to-offices.txt
- e2e/testRigor/rules/close-popup.txt
- e2e/testRigor/rules/create-organization.txt
- e2e/testRigor/rules/navigate-to-admin-users-management.txt
- e2e/testRigor/rules/logout.txt
- e2e/testRigor/testcases/create-client.txt
- e2e/cypress/support/index.ts
- e2e/.eslintrc.json
- e2e/testRigor/README.md
- cypress/support/commands.ts
- e2e/testRigor/testcases/edit-mandatory-fields-of-organization.txt
- e2e/cypress/tsconfig.json
- e2e/tsconfig.json
- cypress/tsconfig.json
- e2e/tsconfig.e2e.json
- e2e/testRigor/testcases/edit-organization.txt
- e2e/testRigor/rules/delete-client.txt
- e2e/testRigor/testcases/logout.txt
- e2e/testRigor/testcases/delete-admin-user.txt
- e2e/testRigor/rules/delete-admin-user.txt
- e2e/cypress/plugins/index.ts
- e2e/testRigor/testcases/login.txt
- e2e/testRigor/rules/pick-today-date.txt
- e2e/testRigor/rules/validate-login-page.txt
- e2e/testRigor/testcases/create-account.txt
- e2e/cypress.json
- e2e/testRigor/testcases/invalid-login.txt
- e2e/testRigor/rules/log-in-and-validate.txt
- e2e/testRigor/testcases/create-new-office.txt
- e2e/testRigor/rules/create-client.txt
- e2e/testRigor/rules/navigate-to-clients.txt
- e2e/testRigor/rules/create-account.txt
- cypress/support/e2e.ts
- cypress/e2e/spec.cy.ts
- e2e/testRigor/testcases/delete-client.txt
- e2e/testRigor/rules/pick-birthdate.txt
- e2e/testRigor/run_testrigor_tests.sh
- cypress/e2e/audit-trails.cy.ts
- e2e/testRigor/rules/create-admin-user.txt
- e2e/testRigor/testcases/create-journal-entries.txt
- cypress/plugins/index.ts
- e2e/cypress/support/commands.ts
- angular.json
- package.json
| getLoanDisbursementDetailsData(): DisbursementData[] { | ||
| return JSON.parse(localStorage.getItem('disbursementData')); | ||
| return JSON.parse(localStorage.getItem('disbursementData') ?? 'null'); | ||
| } |
There was a problem hiding this comment.
Incomplete null handling — should return empty array instead of null.
The method signature declares return type DisbursementData[], but JSON.parse('null') returns null, not an array. Any caller expecting an array will encounter runtime errors (e.g., calling .map(), .length, etc. on null).
🐛 Proposed fix to return empty array when no data exists
getLoanDisbursementDetailsData(): DisbursementData[] {
- return JSON.parse(localStorage.getItem('disbursementData') ?? 'null');
+ return JSON.parse(localStorage.getItem('disbursementData') ?? '[]');
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| getLoanDisbursementDetailsData(): DisbursementData[] { | |
| return JSON.parse(localStorage.getItem('disbursementData')); | |
| return JSON.parse(localStorage.getItem('disbursementData') ?? 'null'); | |
| } | |
| getLoanDisbursementDetailsData(): DisbursementData[] { | |
| return JSON.parse(localStorage.getItem('disbursementData') ?? '[]'); | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/app/loans/loans.service.ts` around lines 827 - 829,
getLoanDisbursementDetailsData currently parses
localStorage.getItem('disbursementData') which can yield null
(JSON.parse('null') -> null) but the method signature expects
DisbursementData[]; change the method to check the stored value and return an
empty array when missing or parsed result is null/invalid. Locate
getLoanDisbursementDetailsData and implement a guard that reads the raw string,
returns [] if raw is null/empty, otherwise JSON.parse and validate/cast to
DisbursementData[] (or default to []) before returning so callers always receive
an array.
|
|
||
| /** Angular Imports */ | ||
| import { Component, OnInit, ViewChild, inject } from '@angular/core'; | ||
| import { ChangeDetectionStrategy, Component, OnInit, ViewChild, inject } from '@angular/core'; |
There was a problem hiding this comment.
OnPush change detection incompatible with imperative state mutation.
The component now uses ChangeDetectionStrategy.OnPush but directly mutates this.dividendData in the route subscription (line 96) without triggering change detection. With OnPush, the view won't update when the subscription callback runs, causing the table to appear empty.
🔧 Recommended fix: Inject ChangeDetectorRef and trigger detection
-import { ChangeDetectionStrategy, Component, OnInit, ViewChild, inject } from '`@angular/core`';
+import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit, ViewChild, inject } from '`@angular/core`'; export class ShareProductsDividendsComponent implements OnInit {
private route = inject(ActivatedRoute);
private router = inject(Router);
+ private cdr = inject(ChangeDetectorRef); constructor() {
this.route.data.subscribe((data: { dividends: any }) => {
this.dividendData = data.dividends.pageItems;
+ this.cdr.markForCheck();
});
}Alternatively, consider using the async pipe pattern to let Angular handle change detection automatically.
Also applies to: 42-42, 95-97
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@src/app/products/share-products/dividends-share-product/dividends.components.ts`
at line 10, The component uses ChangeDetectionStrategy.OnPush but mutates
this.dividendData inside the route subscription in DividendsComponent so the
view won't update; inject ChangeDetectorRef (via constructor or inject()) into
the component and after you update dividendData in the route subscription call
cdr.markForCheck() (or cdr.detectChanges()) to trigger change detection;
alternatively refactor dividendData to an Observable and expose it to the
template via async pipe instead of imperative mutation.
Description
A technical cleanup covering the next areas:
preloadClientsalways truthy inenvironment.tsJSON.parse(null)ingetLoanDisbursementDetailsDatahonobasic-ftptarChangeDetectionStrategy.OnPushcoverage across all componentsRelated issues and discussion
WEB-968
Screenshots, if any
Checklist
Please make sure these boxes are checked before submitting your pull request - thanks!
If you have multiple commits please combine them into one commit by squashing them.
Read and understood the contribution guidelines at
web-app/.github/CONTRIBUTING.md.Summary by CodeRabbit
Chores
Bug Fixes
Refactor