Memory Leak and Uncontrolled Navigation via Uncleared Timeouts in Mentorship Admin Pages
- Dominant language
- Python
- Stars
- 451
- Forks
- 702
- Avg merge
- 22h 59m
- Merged PRs (30d)
- 91
Description
**Describe the bug**
I found a memory leak in three of the mentorship admin pages. We're using `setTimeout` to bounce unauthorized users back to the main programs page, but the timer isn't being cleared if the user navigates away before it fires. This causes a "ghost redirect" where the app suddenly yanks the user back to `/my/mentorship/programs` even if they've already moved on to a completely different section of the site.
**To Reproduce**
Steps to reproduce the behavior:
1. Log in with a standard account (not a program admin).
2. Go straight to `/my/mentorship/programs/[any-program]/edit`.
3. You'll see the "Access Denied" toast.
4. **Quickly** click the "Back" button or use the sidebar to go somewhere else (like Settings).
5. Wait about a second. You'll be unexpectedly redirected to the mentorship programs list, even though you were already on a different page.
**Expected behavior**
The redirect should be cancelled the moment the component unmounts. If the user leaves the page manually, the code should stop trying to move them.
**Are you going to work on fixing this?**
- [x] Yes
- [ ] No
**Screenshots**
N/A — This is a lifecycle/logic bug, so there isn't much to show visually.
**Desktop (please complete the following information):**
- OS: All
- Browser: All
- Version: Latest
**Smartphone (please complete the following information):**
- Device: All
- OS: iOS/Android
- Browser: All
**Additional context**
I noticed this same logic is missing in three specific files:
* `frontend/src/app/my/mentorship/programs/[programKey]/edit/page.tsx`
* `frontend/src/app/my/mentorship/programs/[programKey]/modules/create/page.tsx`
* `frontend/src/app/my/mentorship/programs/[programKey]/modules/[moduleKey]/edit/page.tsx`
We should follow the same cleanup pattern used in `ScrollToTop.tsx` to keep things consistent across the project. I'm happy to put up a PR for this.
Contributor guide
Assessment
This issue has not been assessed yet.