-3

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 players array is reset to defaultPlayers;

    • 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 localStorage during 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 the userStats object is cleared in handleExit().

  • The previous player’s data is not removed from the players array, even though handleExit() 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

  1. Why do old userStats and players data keep reappearing after deploying to Firebase, even though they are cleared in the handleExit function?

  2. What is the correct way to clear and reinitialize:

    • the userStats object,

    • the players array,

    • the data in localStorage,
      so that each new session starts from scratch, as it does in local development?

  3. Is it possible that usePersistedState or 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?

New contributor
Ken_ chik is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.