I've encountered an issue that appears only after deploying to Firebase Hosting — everything works perfectly during local development.
🟢 How it works locally
During local development, the player’s data is correctly stored and cleared:
When the user clicks the Exit button:
their statistics and data are completely removed from
localStorage;the
playersarray is reset todefaultPlayers;the user is redirected back to the Login page.
When they log in again (with the same nickname or a new one), the previous player's statistics do not persist — they are only stored in
localStorageduring the game session and fully cleared after exiting.
🔴 The issue after deploying to Firebase
After deploying to Firebase Hosting, the behavior changes:
After one player exits via the Exit button, the next player receives the previous player’s statistics from
localStorage, even though theuserStatsobject is cleared inhandleExit().The previous player’s data is not removed from the
playersarray, even thoughhandleExit()reinitializes it:
setPlayers(defaultPlayers);
However, in a new session, the new player still sees the previous player in the leaderboard table.
It looks like localStorage.removeItem() or state resetting does not work properly in production — even though everything works correctly locally.
❓ Questions
Why do old
userStatsandplayersdata keep reappearing after deploying to Firebase, even though they are cleared in thehandleExitfunction?What is the correct way to clear and reinitialize:
the
userStatsobject,the
playersarray,the data in
localStorage,
so that each new session starts from scratch, as it does in local development?
Is it possible that
usePersistedStateor React’s state update mechanism behaves differently in production?
📎 Source Code
GitHub (main branch):
https://github.com/Neo-o-svg/Tic-tac-toe-task01/tree/main
Firebase Hosting URL:
https://tic-tac-toe-reactapp.web.app
I would greatly appreciate any insights — what am I missing, and how can I correctly reset the data so that a new player does not inherit the previous player's statistics?