Skip to content

WEB-968: Memory leaks, bugs and build hygiene#3618

Open
alberto-art3ch wants to merge 1 commit into
openMF:devfrom
alberto-art3ch:WEB-968/tech-debt-memory-leaks-bugs-build-hygiene
Open

WEB-968: Memory leaks, bugs and build hygiene#3618
alberto-art3ch wants to merge 1 commit into
openMF:devfrom
alberto-art3ch:WEB-968/tech-debt-memory-leaks-bugs-build-hygiene

Conversation

@alberto-art3ch
Copy link
Copy Markdown
Collaborator

@alberto-art3ch alberto-art3ch commented May 27, 2026

Description

A technical cleanup covering the next areas:

  • Two minor bug fixes,
    • Bug: preloadClients always truthy in environment.ts
    • Bug: JSON.parse(null) in getLoanDisbursementDetailsData
  • Removal of unused production dependencies,
    • hono
    • basic-ftp
    • tar
  • Consolidation of the E2E stack into a single framework, and
  • ChangeDetectionStrategy.OnPush coverage across all components

Related 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

    • Removed Cypress end-to-end testing framework and all associated configurations.
    • Removed TestRigor test scripts and test cases.
    • Cleaned up unused npm dependencies.
  • Bug Fixes

    • Fixed null pointer handling in loan disbursement data retrieval.
  • Refactor

    • Improved reactive form subscription management across multiple components for better resource cleanup.
    • Enhanced change detection performance in dividends component.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 27, 2026

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

⚠️ Parsing warnings (1)
Validation error: Unrecognized key: "pre_merge_checks"
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Walkthrough

This PR removes the Cypress E2E testing framework and testRigor test automation suite, then applies lifecycle-aware RxJS subscription management via DestroyRef and takeUntilDestroyed across multiple components. It also includes minor improvements to service error handling, change detection strategy, and environment configuration defaults.

Changes

Cypress and testRigor Test Framework Removal

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/environments/environment.ts (1)

65-65: ⚡ Quick win

Consider 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 boolean false (see lines 91, 98). If window.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) and mifosRemittanceEnabled (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

📥 Commits

Reviewing files that changed from the base of the PR and between ee46176 and 2a211b2.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json and included by **/*
📒 Files selected for processing (54)
  • angular.json
  • cypress/e2e/audit-trails.cy.ts
  • cypress/e2e/spec.cy.ts
  • cypress/plugins/index.ts
  • cypress/support/commands.ts
  • cypress/support/e2e.ts
  • cypress/tsconfig.json
  • 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/testRigor/README.md
  • e2e/testRigor/rules/close-popup.txt
  • e2e/testRigor/rules/create-account.txt
  • e2e/testRigor/rules/create-admin-user.txt
  • e2e/testRigor/rules/create-client.txt
  • e2e/testRigor/rules/create-organization.txt
  • e2e/testRigor/rules/delete-admin-user.txt
  • e2e/testRigor/rules/delete-client.txt
  • e2e/testRigor/rules/log-in-and-validate.txt
  • e2e/testRigor/rules/logout.txt
  • e2e/testRigor/rules/navigate-to-accounting-creation.txt
  • e2e/testRigor/rules/navigate-to-admin-users-management.txt
  • e2e/testRigor/rules/navigate-to-clients.txt
  • e2e/testRigor/rules/navigate-to-offices.txt
  • e2e/testRigor/rules/pick-birthdate.txt
  • e2e/testRigor/rules/pick-today-date.txt
  • e2e/testRigor/rules/validate-login-page.txt
  • e2e/testRigor/run_testrigor_tests.sh
  • e2e/testRigor/testcases/create-account.txt
  • e2e/testRigor/testcases/create-admin-user.txt
  • e2e/testRigor/testcases/create-client.txt
  • e2e/testRigor/testcases/create-journal-entries.txt
  • e2e/testRigor/testcases/create-new-office.txt
  • e2e/testRigor/testcases/delete-admin-user.txt
  • e2e/testRigor/testcases/delete-client.txt
  • e2e/testRigor/testcases/edit-mandatory-fields-of-organization.txt
  • e2e/testRigor/testcases/edit-organization.txt
  • e2e/testRigor/testcases/invalid-login.txt
  • e2e/testRigor/testcases/login.txt
  • e2e/testRigor/testcases/logout.txt
  • e2e/tsconfig.e2e.json
  • e2e/tsconfig.json
  • package.json
  • 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/loans/loans.service.ts
  • src/app/products/share-products/dividends-share-product/dividends.components.ts
  • src/app/system/audit-trails/audit-trails.component.ts
  • src/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

Comment on lines 827 to 829
getLoanDisbursementDetailsData(): DisbursementData[] {
return JSON.parse(localStorage.getItem('disbursementData'));
return JSON.parse(localStorage.getItem('disbursementData') ?? 'null');
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

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.

Suggested change
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';
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant