From 6a12bdb1790dd79f98815021386f40a6179d7e91 Mon Sep 17 00:00:00 2001 From: Martin Berka Date: Mon, 7 Sep 2026 13:02:45 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20oprava=20spojen=C3=AD=20p=C5=99i=20pou?= =?UTF-8?q?=C5=BE=C3=ADt=C3=AD=20tla=C4=8D=C3=ADtka=20"Zp=C4=9Bt"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/App.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/client/src/App.tsx b/client/src/App.tsx index 3dfb51d..86925d3 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -63,13 +63,15 @@ function App() { const settings = useSettings(); const navigate = useNavigate(); const [easterEgg, _] = useEasterEgg(auth); - const [isConnected, setIsConnected] = useState(false); + const socket = useContext(SocketContext); + // Socket je singleton mimo React, takže při návratu v historii prohlížeče (remount + // komponenty) už žádný "connect" event nepřijde - stav proto inicializujeme z něj + const [isConnected, setIsConnected] = useState(() => socket.connected); const [data, setData] = useState(); const [food, setFood] = useState(); const [myOrder, setMyOrder] = useState(); const [foodChoiceList, setFoodChoiceList] = useState(); const [closed, setClosed] = useState(false); - const socket = useContext(SocketContext); const choiceRef = useRef(null); const foodChoiceRef = useRef(null); const departureChoiceRef = useRef(null); @@ -121,6 +123,8 @@ function App() { // Registrace socket eventů useEffect(() => { + // Srovnání se skutečným stavem socketu (mohl se změnit mezi renderem a efektem) + setIsConnected(socket.connected); socket.on(EVENT_CONNECT, () => { setIsConnected(true); });