Aman-Mittal opened a new issue, #423:
URL: https://github.com/apache/fineract-backoffice-ui/issues/423

   Good first issue. One file, a few lines, and the convention to follow is 
already used elsewhere in this repo.
   
   ## What is wrong
   
   `src/app/layout/header.component.ts:465` starts a one-minute interval to 
refresh the "Render Time" display and never stops it:
   
   ```ts
   const updateTime = () => {
     this.renderTime.set(
       new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' 
}),
     );
   };
   updateTime();
   setInterval(updateTime, 60_000);   // <-- never cleared
   ```
   
   `HeaderComponent` implements `OnInit` but not `OnDestroy`, and nothing 
anywhere calls `clearInterval`.
   
   ## Why it matters
   
   The header is destroyed and rebuilt whenever the user leaves the 
authenticated layout — signing out is the ordinary case. The old interval 
survives that, holding a closure over the destroyed component's `renderTime` 
signal, and the new header starts another. Sign out and back in three times and 
three timers are ticking, two of them writing to components nobody can see.
   
   Nothing breaks visibly, which is why it has gone unnoticed — it is wasted 
work and a small leak that grows with session length. It also keeps firing 
while the tab is in the background.
   
   This is the **only** `setInterval` in `src/app`, so fixing it here fixes it 
everywhere:
   
   ```
   $ grep -rn "setInterval(" src/app --include=*.ts | grep -v spec | grep -v 
"\.test\."
   src/app/layout/header.component.ts:465:    setInterval(updateTime, 60_000);
   ```
   
   ## The fix
   
   Either keep the handle and clear it in `ngOnDestroy`, or — preferred, and 
already the convention here — let Angular tear it down. `DestroyRef` and 
`takeUntilDestroyed` are used in `src/app/core/services/idle.service.ts`, 
`src/app/features/login/login.component.ts` and three other files; follow 
whichever of those reads closest.
   
   A sketch of the `DestroyRef` form:
   
   ```ts
   private readonly destroyRef = inject(DestroyRef);
   // ...
   const id = setInterval(updateTime, 60_000);
   this.destroyRef.onDestroy(() => clearInterval(id));
   ```
   
   ## A question worth raising in the PR
   
   While you are in here: "Render Time" shows the viewer's own wall clock, 
relabelled in developer language, next to "Business Date" — which is the value 
that actually governs what the platform does. If you think it earns its place 
in a banking back-office header, say so in the PR; if you think it does not, 
that is worth a separate issue rather than folding a removal into this fix.
   
   ## Verifying
   
   Add a test under `src/app/layout/` (Vitest — `*.test.ts`, see CONTRIBUTING) 
that destroys the fixture and asserts the timer stopped; `vi.useFakeTimers()` 
plus `vi.getTimerCount()` is the direct way. Then `npm run test:unit`.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to