Skip to content

fix(pwa,tracking): extract clearState helper, consolidate depth counter into navDepthRef, fix Tailwind utilities#583

Merged
devakesu merged 4 commits into3.0.4from
copilot/sub-pr-582
Mar 6, 2026
Merged

fix(pwa,tracking): extract clearState helper, consolidate depth counter into navDepthRef, fix Tailwind utilities#583
devakesu merged 4 commits into3.0.4from
copilot/sub-pr-582

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 5, 2026

Pull Request

Description

Addresses unresolved review comments from PR #582. Fixes unreliable history.length-based deep-back detection in useBackToExit, eliminates duplicated ref-reset logic across toast callbacks, and corrects two non-standard Tailwind utility classes in TrackingClient.

useBackToExit.tsclearState() helper

onDismiss/onAutoClose previously inlined the same 5-ref reset already in resetExitState(). Extracted clearState() — resets exit-state refs without calling toast.dismiss() (avoids re-entrant dismissals). resetExitState() now calls toast.dismiss() + clearState(); the toast callbacks reference clearState directly.

// Before: 5-line inline block duplicated in onDismiss AND onAutoClose
onDismiss: () => {
  toastIdRef.current = null;
  firstBackTimeRef.current = null;
  nonDashboardBackCountRef.current = 0;
  exitArmedRef.current = false;
  exitModeRef.current = null;
},

// After: single shared helper
const clearState = () => { /* resets refs including navDepthRef, no toast.dismiss() */ };
const resetExitState = () => { toast.dismiss(toastIdRef.current); clearState(); };
// ...
onDismiss: clearState,
onAutoClose: clearState,

useBackToExit.tsnavDepthRef replaces both history.length and nonDashboardBackCountRef

history.length is a session-wide counter that never decreases on back navigation, causing misclassification of shallow positions as "deep". Replaced with navDepthRef — a hook-internal counter that serves as the single source of truth for qualifying non-dashboard back presses. The separate nonDashboardBackCountRef has been removed; navDepthRef now drives both depth tracking and the >= 2 deep-mode toast gate.

Key semantics:

  • Incremented after any resetExitState() branches so each new sequence starts at 1
  • Included in clearState() so toast expiry/dismiss resets the count, requiring a fresh 2-press sequence
  • Reset to 0 on sentinel hit, dashboard route visit, and deep-mode close

TrackingClient.tsx — Tailwind utility fixes

  • backdrop-blur-xsbackdrop-blur-sm (no xs blur in Tailwind's default scale)
  • top-22top-[88px] (no 22 in Tailwind's default spacing scale)

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code refactoring
  • Performance improvement
  • Test updates

Related Issues

Relates to #582

Changes Made

  • Extracted clearState() helper inside useEffect; onDismiss/onAutoClose now reference it instead of duplicating inline reset blocks
  • Removed nonDashboardBackCountRef; consolidated into navDepthRef as the single qualifying-back-press counter
  • navDepthRef added to clearState() so toast expiry resets the count; incremented after resetExitState() branches so sequences always start at 1
  • navDepthRef.current >= 2 gates the deep-mode exit toast (replaces nonDashboardBackCountRef.current >= 2)
  • backdrop-blur-xsbackdrop-blur-sm and top-22top-[88px] in TrackingClient.tsx
  • Removed now-irrelevant history.pushState setups from tests that only existed to inflate history.length; updated affected test description

Version Bump

  • Version automatically bumped by workflow (same-repo PRs)
  • Version manually bumped using node scripts/bump-version.js (fork PRs)
  • Version already up-to-date (no bump needed)

Testing

Test Environment

  • Node version: 22
  • npm version: 10
  • OS: Linux

Tests Performed

  • Unit tests pass (npm run test)
  • E2E tests pass (npm run test:e2e)
  • Linting passes (npm run lint)
  • Manual testing completed

Test Coverage

All 20 useBackToExit unit tests pass. Tests updated to reflect that depth tracking no longer depends on history.length and that the single navDepthRef counter drives the deep-mode gate.

Documentation

  • Documentation updated (if needed)
  • Code comments added for complex logic
  • API documentation updated (if API changes)

Checklist

  • My code follows the project's code style
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings or errors
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Screenshots (if applicable)

N/A

Additional Notes

navDepthRef is now the single counter for both "how deep has the user navigated?" and "how many qualifying back presses have occurred in this sequence?". It resets in clearState() on toast expiry/dismiss so the user must press back twice again for a fresh deep-mode trigger, and resets to 0 at sentinel/dashboard/close so deep-mode counting always restarts cleanly from a root or shallow position.


For maintainers:

  • PR title follows conventional commit format
  • Version bump is correct
  • All checks pass
  • Documentation is complete
  • Ready to merge

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI mentioned this pull request Mar 5, 2026
10 tasks
Copilot AI and others added 2 commits March 5, 2026 21:28
…p-back tracking, fix Tailwind utilities

Co-authored-by: devakesu <61821107+devakesu@users.noreply.github.com>
…onal separation from clearState

Co-authored-by: devakesu <61821107+devakesu@users.noreply.github.com>
Copilot AI changed the title [WIP] Enhance tracking page UX and update legal policy fix(pwa,tracking): extract clearState helper, use navDepthRef for depth tracking, fix Tailwind utilities Mar 5, 2026
@devakesu devakesu marked this pull request as ready for review March 5, 2026 21:33
@devakesu devakesu self-requested a review as a code owner March 5, 2026 21:33
Copilot AI review requested due to automatic review settings March 5, 2026 21:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors and fixes the standalone-PWA “double back to exit” behavior and cleans up tracking UI styling, primarily addressing follow-up items from PR #582.

Changes:

  • Extracts a shared clearState() helper in useBackToExit to dedupe toast-dismiss reset logic.
  • Replaces the previous history.length-based deep/back detection approach with a hook-internal depth ref (navDepthRef) and updates tests accordingly.
  • Fixes non-standard Tailwind utility classes used in the tracking client UI.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/hooks/useBackToExit.ts Refactors exit-state resets and changes deep/back detection logic for standalone PWA behavior.
src/hooks/tests/useBackToExit.test.ts Updates unit tests to align with the new depth/back detection approach.
src/app/(protected)/tracking/TrackingClient.tsx Replaces invalid Tailwind utilities with supported/default/arbitrary equivalents.
package-lock.json Updates lockfile after dependency resolution changes during install.

Comment on lines +127 to 131
if (!isDashboardRoute) {
// Track depth within the hook — more reliable than history.length,
// which is a session-wide counter that never decreases on back navigation.
navDepthRef.current += 1;
const now = Date.now();
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

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

navDepthRef is incremented here but never read to make any decision (it only ever gets reset). That means the previous “deep history” gating was effectively removed, and the new counter currently doesn’t influence when the deep-mode exit flow should apply. Either wire navDepthRef into the deep/back detection logic (and/or replace nonDashboardBackCountRef), or remove it to avoid misleading depth-tracking semantics.

Copilot uses AI. Check for mistakes.
@devakesu
Copy link
Copy Markdown
Owner

devakesu commented Mar 6, 2026

@copilot apply changes based on the comments in this thread

…ve nonDashboardBackCountRef

Co-authored-by: devakesu <61821107+devakesu@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 6, 2026

@copilot apply changes based on the comments in this thread

Fixed in b61fc5a. Removed nonDashboardBackCountRef entirely and consolidated it into navDepthRef:

  • navDepthRef.current = 0 added to clearState() — toast expiry/dismiss resets the count, requiring a fresh 2-press sequence
  • navDepthRef.current += 1 moved to after all resetExitState() branches, so the count correctly starts at 1 in each new sequence (not counting the press that triggers a reset)
  • navDepthRef.current >= 2 now drives the deep-mode toast gate
  • Redundant explicit depth resets removed (all handled by clearState() inside resetExitState())

Copilot AI changed the title fix(pwa,tracking): extract clearState helper, use navDepthRef for depth tracking, fix Tailwind utilities fix(pwa,tracking): extract clearState helper, consolidate depth counter into navDepthRef, fix Tailwind utilities Mar 6, 2026
@devakesu devakesu merged commit 26ec659 into 3.0.4 Mar 6, 2026
@devakesu devakesu deleted the copilot/sub-pr-582 branch March 6, 2026 02:04
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>
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.

3 participants