Skip to content

Commit 930bd9c

Browse files
committed
fix(WebSocketPolyfill): run onopen callback on initialization
After a long offline period (>70 seconds), y-websocket's internal watchdog closes the WebSocketPolyfill instance because no messages have been received. After going back online, y-websocket creates a new WebSocketPolyfill instance to reconnect. In the new instance, syncService.open() is called — but it returns early because the HTTP session is still alive. This results in `wsconnected` staying false, which means that new steps never get pushed to the server. The fix is to run onopen callback explicitly in WebSocketPolyfill's constructor. Signed-off-by: Jonas <jonas@freesources.org>
1 parent 21deb81 commit 930bd9c

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

src/services/WebSocketPolyfill.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ export default function initWebSocketPolyfill(
6666
syncService.bus.on('sync', this.#onSync)
6767

6868
syncService.open()
69+
if (syncService.hasActiveConnection()) {
70+
setTimeout(() => this.onopen?.(), 0)
71+
}
6972
}
7073

7174
/**

0 commit comments

Comments
 (0)