Conversation
…, fix activeCourseMeta lookups Co-authored-by: devakesu <61821107+devakesu@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Improve tracking UX and align legal policy updates
fix(pwa,tracking): toast race condition, scroll setState deduplication, activeCourseMeta lookup trim consistency
Mar 6, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a couple of correctness edge cases and reduces unnecessary rendering work in PWA/back-navigation and the tracking page, improving stability and scroll performance in GhostClass.
Changes:
- Prevents stale Sonner toast callbacks from clearing state for a newer “press back again to exit” toast in
useBackToExit. - Deduplicates scroll/resize-driven React state updates and throttles the active-course header computation with
requestAnimationFrame. - Fixes
activeCourseMetalookups to use the trimmedactiveCourseKeyconsistently.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/hooks/useBackToExit.ts |
Guards toast clear callbacks by toast-id identity to avoid race conditions during dismiss/create cycles. |
src/app/(protected)/tracking/TrackingClient.tsx |
Adds RAF throttling + last-value refs to avoid redundant re-renders and ensures trimmed key is used for active course metadata lookups. |
devakesu
added a commit
that referenced
this pull request
Mar 6, 2026
* feat(tracking,legal): improve tracking UX and align legal policy updates - add sticky course headers on tracking page - add right-side scroll-to-bottom floating button near tracking controls - switch accept-terms success navigation to router.replace to prevent back nav to terms - update legal policy text (Turnstile clarity, AWS ap-south-1 disclosure, Kochi jurisdiction) - bump terms version to 2.5 and align legal effective date docs/env examples - enhance legal page external link visibility and secure external link behavior - update related tests and mocks (tracking + save-token terms version) * fix(tracking,pwa): refine pinned course header and reset deep back-exit state - use header-based scroll detection for pinned course title timing - adjust scroll-to-end FAB margins slightly on mobile and md breakpoints - reset non-dashboard back counter when exit state/toast is cleared - add regression test for deep-mode threshold expiry re-arming behavior * fix(pwa,tracking): extract clearState helper, consolidate depth counter into navDepthRef, fix Tailwind utilities (#583) * Initial plan * fix(pwa,tracking): extract clearState helper, use navDepthRef for deep-back tracking, fix Tailwind utilities Co-authored-by: devakesu <61821107+devakesu@users.noreply.github.com> * refine(pwa): clarify navDepthRef semantics and add comment on intentional separation from clearState Co-authored-by: devakesu <61821107+devakesu@users.noreply.github.com> * fix(pwa): merge navDepthRef into single qualifying-back counter, remove nonDashboardBackCountRef Co-authored-by: devakesu <61821107+devakesu@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: devakesu <61821107+devakesu@users.noreply.github.com> * fix(pwa,tracking): toast race condition, scroll setState deduplication, activeCourseMeta lookup trim consistency (#584) * Initial plan * fix(tracking,pwa): guard toast callbacks, deduplicate scroll setState, fix activeCourseMeta lookups Co-authored-by: devakesu <61821107+devakesu@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: devakesu <61821107+devakesu@users.noreply.github.com> * fix(tracking): remove unused cardVariants and improve toast dismissal logic in useBackToExit * fix(legal): normalize legal effective date format and improve handling * Update src/app/config/legal.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Devanarayanan <fusion@devakesu.com> * fix(tracking,hooks): aria-hidden decorative icons + accurate stale comments (#585) * Initial plan * fix(tracking,hooks): add aria-hidden to decorative BookOpen icons and update stale comments Co-authored-by: devakesu <61821107+devakesu@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: devakesu <61821107+devakesu@users.noreply.github.com> --------- Signed-off-by: Devanarayanan <fusion@devakesu.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three correctness/perf bugs identified in PR review thread #582, addressed together.
Description
useBackToExit— toast callback race conditionWhen
showExitToast()dismissed an old toast and immediately created a new one, Sonner's async exit animation could fire the old toast'sonDismiss/onAutoCloseafter the new toast was registered, resettingfirstBackTimeRef,exitArmedRef, andexitModeReffor the live toast. Fixed by capturing the toast id in a closure and guardingclearState()behind an identity check:TrackingClient— scroll/resize handler redundant re-rendersupdateActiveCoursecalledsetActiveCourseKey+setShowPinnedCourseunconditionally on every scroll/resize event, even when the computed value was unchanged. AddedlastActiveCourseKeyRef/lastShowPinnedCourseRefto gate setState to actual changes. Also wrapped the event handler inrequestAnimationFramethrottling so rapid bursts incur at most one layout read + setState per frame.TrackingClient—activeCourseMetalookup trim mismatchdisplayCourseNameandcourseCodewere looked up usingitems[0].course(raw, untrimmed) while grouping keys are keyed onitem.course.trim(). Replaced withactiveCourseKey(already trimmed) to guarantee lookup hits.Type of Change
Related Issues
Relates to #582
Changes Made
src/hooks/useBackToExit.ts: scopeonDismiss/onAutoClosecallbacks to their toast id via closure guard to prevent stale callbacks clearing active toast statesrc/app/(protected)/tracking/TrackingClient.tsx: addlastActiveCourseKeyRef+lastShowPinnedCourseRef; gatesetActiveCourseKey/setShowPinnedCourseto value changes only; add RAF throttle on scroll/resize handlersrc/app/(protected)/tracking/TrackingClient.tsx: useactiveCourseKey(trimmed) instead ofitems[0].courseforattendanceData/coursesDatalookups inactiveCourseMetaVersion Bump
node scripts/bump-version.js(fork PRs)Testing
Test Environment
Tests Performed
npm run test)npm run test:e2e)npm run lint)Test Coverage
30 existing unit tests across
useBackToExitandTrackingClientsuites pass with no modifications required.Documentation
Checklist
Screenshots (if applicable)
N/A — logic-only changes, no UI visual delta.
Additional Notes
The
newToastId = nullinitialization inshowExitToastis intentional:handleClearmust capture the variable by reference (not value) beforetoast()is called, making alet+ deferred assignment the only viable pattern for this circular closure dependency.For maintainers:
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.