From bc27decdf9854f26d7bf4afbe464461b2716eae5 Mon Sep 17 00:00:00 2001 From: Daniel Isenmann Date: Wed, 27 May 2026 15:02:28 +0200 Subject: [PATCH] Fixed a problem where mobile view doesn't work --- .../src/services/LiverpoolHubService.js | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/Liverpool/ClientApp/src/services/LiverpoolHubService.js b/Liverpool/ClientApp/src/services/LiverpoolHubService.js index 8da7fda..5dee013 100644 --- a/Liverpool/ClientApp/src/services/LiverpoolHubService.js +++ b/Liverpool/ClientApp/src/services/LiverpoolHubService.js @@ -4,12 +4,25 @@ class LiverpoolHubService { constructor() { this.userName = ''; this.gameName = ''; + this._gameUpdatedCallback = null; + this._pendingGameUpdate = null; const hubConnection = new signalR.HubConnectionBuilder() .withUrl("/liverpoolHub") .withAutomaticReconnect([500, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 15000, 20000, null]) .configureLogging(signalR.LogLevel.Information) .build(); + + // Pre-register so GameUpdate is never dropped while React is still mounting + // after the GameStarted navigation (race condition on real mobile devices). + hubConnection.on('GameUpdate', (game) => { + if (this._gameUpdatedCallback) { + this._gameUpdatedCallback(game); + } else { + this._pendingGameUpdate = game; + } + }); + hubConnection.start().then(() => { if(this.userName === '') { this.userName = hubConnection.connectionId; @@ -148,9 +161,12 @@ class LiverpoolHubService { } registerGameUpdated(gameUpdated) { - this.connection.on('GameUpdate', (game) => { - gameUpdated(game); - }); + this._gameUpdatedCallback = gameUpdated; + if (this._pendingGameUpdate) { + const pending = this._pendingGameUpdate; + this._pendingGameUpdate = null; + gameUpdated(pending); + } } registerCardMovedAnimation(callback) {