fix(auth): make SessionManager.registerRefreshHook idempotent for HMR#1045
Merged
yahyafakhroji merged 1 commit intomainfrom Mar 3, 2026
Merged
fix(auth): make SessionManager.registerRefreshHook idempotent for HMR#1045yahyafakhroji merged 1 commit intomainfrom
yahyafakhroji merged 1 commit intomainfrom
Conversation
The singleton SessionManager survives Vite HMR, but entry.ts re-executes on every hot reload — calling registerRefreshHook() again on the same instance. The previous throw guard caused a crash that blocked the UI during local development. Replace the throw with a simple overwrite so repeated registrations replace the previous hook instead of erroring.
gaghan430
approved these changes
Mar 3, 2026
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.
Problem
During local development, Vite HMR re-executes
entry.tson every hot reload. ThesessionManagersingleton survives the reload (module-scoped), butregisterRefreshHook()gets called again — hitting the "already registered" guard and throwing an error that crashes the Vite error overlay, blocking the UI until a manual tab reload.Root Cause
The
registerRefreshHook()method was designed to throw on duplicate registration to prevent multiple consumers from eavesdropping on raw access tokens. However, in Vite's HMR cycle, it's the same consumer (entry.ts) re-registering — not a different one.Fix
Make
registerRefreshHook()idempotent — repeated calls replace the previous hook instead of throwing. This is safe because:Changes
app/utils/auth/session-manager.ts— remove throw guard, replace with simple overwritecypress/component/session-manager.cy.ts— update test: verify replacement behavior instead of expecting throw