fix(frontend): reconnect stream on same-session resume

This commit is contained in:
User
2026-07-14 20:53:19 +02:00
parent b1d1284cc8
commit 1393c6358e
5 changed files with 90 additions and 47 deletions
@@ -46,3 +46,17 @@ test("closes the stream on unmount", () => {
unmount();
expect(es.closed).toBe(true);
});
test("reconnects the same session when the generation changes", () => {
const { rerender } = renderHook(
({ generation }) => useSessionStream("s1", generation),
{ initialProps: { generation: 0 } },
);
const first = FakeEventSource.instances[0];
rerender({ generation: 1 });
expect(first.closed).toBe(true);
expect(FakeEventSource.instances).toHaveLength(2);
expect(FakeEventSource.instances[1].url).toBe(first.url);
});
+2 -2
View File
@@ -4,7 +4,7 @@ import { joinBackendPath } from "../api/runtime-config";
import { useSessionStore } from "../store/sessionStore";
import type { StreamEvent } from "../api/types";
export function useSessionStream(sessionId: string | null) {
export function useSessionStream(sessionId: string | null, generation = 0) {
const [connected, setConnected] = useState(false);
const applyEvent = useSessionStore((s) => s.applyEvent);
@@ -40,7 +40,7 @@ export function useSessionStream(sessionId: string | null) {
es.close();
setConnected(false);
};
}, [sessionId, applyEvent]);
}, [sessionId, generation, applyEvent]);
return { connected };
}