feat: Automatically recover from frozen live streams (#2569)

- Closes: #2099
This commit is contained in:
Dermot Duffy
2026-07-07 21:37:24 -07:00
committed by GitHub
parent 9f956fe89f
commit fb1bbc739e
73 changed files with 3321 additions and 364 deletions
@@ -220,4 +220,51 @@ describe('VisibilityObserver', () => {
);
});
});
describe('emitInitial', () => {
it('should emit the initial visible value on the baseline callback', async () => {
const onChange = vi.fn();
const observer = new VisibilityObserver(onChange, { emitInitial: true });
observer.setRoot(createParent());
await callIntersectionHandler(true);
expect(onChange).toHaveBeenCalledTimes(1);
expect(onChange).toHaveBeenCalledWith(true);
});
it('should emit the initial hidden value on the baseline callback', async () => {
const onChange = vi.fn();
const observer = new VisibilityObserver(onChange, { emitInitial: true });
observer.setRoot(createParent());
await callIntersectionHandler(false);
expect(onChange).toHaveBeenCalledTimes(1);
expect(onChange).toHaveBeenCalledWith(false);
});
it('should not re-emit an unchanged state after the initial emit', async () => {
const onChange = vi.fn();
const observer = new VisibilityObserver(onChange, { emitInitial: true });
observer.setRoot(createParent());
await callIntersectionHandler(true);
await callIntersectionHandler(true);
expect(onChange).toHaveBeenCalledTimes(1);
});
it('should still emit subsequent transitions after the initial emit', async () => {
const onChange = vi.fn();
const observer = new VisibilityObserver(onChange, { emitInitial: true });
observer.setRoot(createParent());
await callIntersectionHandler(true);
await callIntersectionHandler(false);
expect(onChange).toHaveBeenNthCalledWith(1, true);
expect(onChange).toHaveBeenNthCalledWith(2, false);
});
});
});