rwsdk 1.5.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/use-synced-state/hibernation/__tests__/client-core.test.js +6 -5
- package/dist/use-synced-state/hibernation/connection/connection.js +1 -4
- package/dist/use-synced-state/hibernation/connection/timer.d.ts +1 -2
- package/dist/use-synced-state/hibernation/connection/timer.js +2 -21
- package/package.json +2 -2
|
@@ -207,17 +207,18 @@ describe("client-core", () => {
|
|
|
207
207
|
await waitForCondition(() => statusChanges.filter((s) => s === "connected").length >= 2 ? true : undefined, 3000);
|
|
208
208
|
expect(statusChanges.filter((s) => s === "connected")).toHaveLength(2);
|
|
209
209
|
});
|
|
210
|
-
it("force-
|
|
210
|
+
it("does not force-close an idle hibernation socket when no messages are received", async () => {
|
|
211
211
|
const client = createClient();
|
|
212
212
|
await client.subscribe("counter", () => { });
|
|
213
213
|
await waitForOpen(clients[0]);
|
|
214
214
|
const firstSocket = clients[0];
|
|
215
|
-
const
|
|
215
|
+
const closeSpy = vi.fn();
|
|
216
|
+
firstSocket.once("close", closeSpy);
|
|
216
217
|
await vi.advanceTimersByTimeAsync(DEAD_CONNECTION_TIMEOUT_MS + 1000);
|
|
217
|
-
|
|
218
|
-
expect(firstSocket.readyState).toBe(WebSocket.
|
|
218
|
+
expect(closeSpy).not.toHaveBeenCalled();
|
|
219
|
+
expect(firstSocket.readyState).toBe(WebSocket.OPEN);
|
|
219
220
|
});
|
|
220
|
-
it("
|
|
221
|
+
it("keeps the socket open across long idle windows between update messages", async () => {
|
|
221
222
|
const client = createClient();
|
|
222
223
|
await client.subscribe("counter", () => { });
|
|
223
224
|
await waitForOpen(clients[0]);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { manager } from "../state/clientManager.js";
|
|
2
2
|
import { reconnect } from "../reconnect/reconnect.js";
|
|
3
3
|
import { sendMessage, makeMessageId, unpackMessage, handleServerMessage } from "./messages.js";
|
|
4
|
-
import {
|
|
4
|
+
import { rejectPending } from "./timer.js";
|
|
5
5
|
export function getConnection(endpoint, webSocketFactory) {
|
|
6
6
|
let connection = manager.getConnection(endpoint);
|
|
7
7
|
if (!connection) {
|
|
@@ -24,11 +24,9 @@ function createConnection(endpoint, webSocketFactory) {
|
|
|
24
24
|
connection.isOpen = true;
|
|
25
25
|
manager.notifyStatusChange(endpoint, "connected");
|
|
26
26
|
manager.resetBackoff(endpoint);
|
|
27
|
-
resetDeadConnectionTimer(connection, endpoint);
|
|
28
27
|
resubscribeAndSync(connection, endpoint);
|
|
29
28
|
});
|
|
30
29
|
connection.ws.addEventListener("message", (event) => {
|
|
31
|
-
resetDeadConnectionTimer(connection, endpoint);
|
|
32
30
|
const message = unpackMessage(event.data);
|
|
33
31
|
if (!message)
|
|
34
32
|
return;
|
|
@@ -36,7 +34,6 @@ function createConnection(endpoint, webSocketFactory) {
|
|
|
36
34
|
});
|
|
37
35
|
connection.ws.addEventListener("close", () => {
|
|
38
36
|
connection.isOpen = false;
|
|
39
|
-
cleanupConnectionTimers(connection);
|
|
40
37
|
rejectPending(connection, "WebSocket closed");
|
|
41
38
|
if (manager.getConnection(endpoint) === connection) {
|
|
42
39
|
manager.deleteConnection(endpoint);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { type Connection } from "./types.js";
|
|
2
2
|
export declare const DEAD_CONNECTION_TIMEOUT_MS = 90000;
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function stopDeadConnectionTimer(connection: Connection): void;
|
|
4
4
|
export declare function rejectPending(connection: Connection, reason: string): void;
|
|
5
|
-
export declare function resetDeadConnectionTimer(connection: Connection, endpoint: string): void;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { manager } from "../state/clientManager.js";
|
|
2
|
-
import { reconnect } from "../reconnect/reconnect.js";
|
|
3
1
|
export const DEAD_CONNECTION_TIMEOUT_MS = 90_000;
|
|
4
|
-
export function
|
|
2
|
+
export function stopDeadConnectionTimer(connection) {
|
|
5
3
|
if (connection.deadConnectionTimer) {
|
|
6
4
|
clearTimeout(connection.deadConnectionTimer);
|
|
7
5
|
connection.deadConnectionTimer = null;
|
|
@@ -12,22 +10,5 @@ export function rejectPending(connection, reason) {
|
|
|
12
10
|
pending.reject(new Error(reason));
|
|
13
11
|
}
|
|
14
12
|
connection.pending.clear();
|
|
15
|
-
|
|
16
|
-
export function resetDeadConnectionTimer(connection, endpoint) {
|
|
17
|
-
if (connection.deadConnectionTimer) {
|
|
18
|
-
clearTimeout(connection.deadConnectionTimer);
|
|
19
|
-
}
|
|
20
|
-
connection.deadConnectionTimer = setTimeout(() => {
|
|
21
|
-
try {
|
|
22
|
-
connection.ws.close();
|
|
23
|
-
}
|
|
24
|
-
catch { }
|
|
25
|
-
connection.isOpen = false;
|
|
26
|
-
rejectPending(connection, "WebSocket timed out");
|
|
27
|
-
cleanupConnectionTimers(connection);
|
|
28
|
-
if (manager.getConnection(endpoint) === connection) {
|
|
29
|
-
manager.deleteConnection(endpoint);
|
|
30
|
-
reconnect(endpoint);
|
|
31
|
-
}
|
|
32
|
-
}, DEAD_CONNECTION_TIMEOUT_MS);
|
|
13
|
+
stopDeadConnectionTimer(connection);
|
|
33
14
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rwsdk",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -237,7 +237,7 @@
|
|
|
237
237
|
"semver": "~7.7.4",
|
|
238
238
|
"tsx": "~4.21.0",
|
|
239
239
|
"typescript": "~6.0.3",
|
|
240
|
-
"vite": "~8.0
|
|
240
|
+
"vite": "~8.1.0",
|
|
241
241
|
"vitest": "~4.1.5",
|
|
242
242
|
"ws": "^8.21.0"
|
|
243
243
|
}
|