Enhance session management and UI state handling

- Added checks to handle session disconnections during confirmation in ServeSession, preventing further actions on a disconnected session.
- Updated App:startSession to manage UI state in one-shot sync mode, ensuring a loading state is displayed instead of a connected page.
- Implemented safety measures in App:endSession to reset UI state if the session reference is cleared, addressing potential race conditions.
This commit is contained in:
Joe 2026-02-07 12:41:13 -06:00
parent a81096c01d
commit 0e263789b0
2 changed files with 58 additions and 9 deletions

View file

@ -278,6 +278,12 @@ function ServeSession:__onWebSocketMessage(messagesPacket)
self.__confirmingPatch = nil
self.__isConfirming = false
-- If the session was disconnected during the confirmation yield
-- (e.g., WebSocket error, server crash), bail out immediately.
if self.__status == Status.Disconnected then
return
end
-- Resume ChangeBatcher after confirmation
self.__changeBatcher:resume()
@ -656,6 +662,13 @@ function ServeSession:__confirmAndApplyInitialPatch(catchUpPatch, serverInfo)
self.__confirmingPatch = nil
self.__isConfirming = false
-- If the session was disconnected during the confirmation yield
-- (e.g., WebSocket error, server crash), bail out immediately.
-- Don't resume batcher or apply patches on a dead session.
if self.__status == Status.Disconnected then
return Promise.reject("Session disconnected during confirmation")
end
-- Resume ChangeBatcher after confirmation
self.__changeBatcher:resume()
end