fix(frontend): reconnect stream on same-session resume
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user