Repository navigation
Auth Role Preservation and Router Re creation Fix 20260416
Stabilized user.roles reference in AuthProvider to prevent unnecessary router recreation on periodic token refresh cycles.
The router was being recreated every 3 minutes during silent authentication token refresh because AppRoutes.tsx depends on user?.roles for route selection. However, parseToken was creating a new FamLoginUser object with a new roles array even when role content hadn't changed. The fix preserves the previous roles array reference when role content is structurally equal, preventing false-positive dependency invalidations.
- PH-1: Router re-created on every auth state change
- Prevent unnecessary router recreation during periodic auth state refreshes
- Eliminate wasteful
useMemoinvalidations inAppRoutescaused by reference churn - Maintain reference stability for authentication state without changing public APIs
- Improve session stability and reduce render cycles triggered by non-substantive auth updates
- Added
preserveRolesReference()helper function inAuthProviderto maintain role reference identity when content is unchanged - Modified
setUser()state update logic to usepreserveRolesReference()instead of simple equality check - Helper co-located with refresh logic for clarity and encapsulation
- Prevents unnecessary router re-creation by preserving
user.rolesreference identity - Eliminates wasteful
useMemoinvalidations inAppRoutesthat depend onuser.roles - Reduces React render cycles triggered by false-positive auth state changes
- Particularly impactful during periodic silent token refresh (every 3 minutes) for all authenticated sessions
- None — public
AuthProviderAPI remains unchanged - Internal optimization fully contained within provider layer
- None — no user-facing changes
- None
- Fixed issue where router was being recreated unnecessarily on every auth state refresh, even when user roles hadn't changed
- Improved router stability during periodic auth token refreshes (occurring every 3 minutes)
- Reduced unnecessary re-renders of components depending on router state
- More efficient auth state management without breaking existing API contracts or component dependencies
- Low-risk fix — isolated to auth provider layer with zero surface-area API changes
- Monitor auth state refresh cycles in production to confirm router stability improvement
- Consider applying similar reference-preservation patterns to other auth attributes (e.g.,
privileges) if similar reference-churn issues arise - Update frontend structure guidelines to document reference-preservation pattern for context providers
This wiki documents NR Waste Plus for users and developers. Verify security and deployment guidance against the current application configuration before applying it elsewhere.
- Report an issue or ask a question in the GitHub repository.
- Follow the Contributing Guidelines to propose an update.
- Read the Code of Conduct.
Collection indexes support human browsing and machine retrieval. Keep both current when adding or moving wiki pages.
NR Waste Plus Wiki | GitHub Repository