v3: the tests learn to expect trouble, and seven bugs they now catch are fixed — a review of the two test-suite commits found them written mostly for the happy path; each fix below comes with the test that fails without it. Infinite scroll: a later page that failed turned loadingMore back off, which made a new IntersectionObserver, which reports a sentinel still in view at once — so an offline feed asked again as fast as the request could fail, on Search, Index, the followed feeds, user dumps and user playlists alike. useInfiniteScroll now waits 1s, 2s, 4s… up to 30s while the sentinel stays put, counted from the last load so re-renders don't restart it, and asks at once again when the sentinel leaves the view or is pushed down by new items; the fake observer in src/test can report an element in view on observe(), as a browser's does. Playlist covers: the row was updated and playlist_updated sent before the file was written, so a client fetching image?v=<new> in between cached the old cover (or a 404) under the new URL for an hour, and a failed write left image_mime set with no file behind it. The file now goes in first, written beside and renamed over, and only then does the row change. Playlist order: the server wanted every member named, but GET hides private dumps the requester can't see, so a playlist holding someone else's dump that went private — or one a moderator reorders around the owner's private dumps — could never be reordered. The requester now orders what they can see and hidden members keep their slots; the visibility rule lives in api/lib/playlist-members.ts, shared by GET, reorder and the socket. playlist_dumps_updated also sent every member's id, private ones included, to a public playlist's whole audience; each viewer now gets the ids they can see, plus a dumpCount of all members so playlist cards keep the server's count. File dumps: replacing the file and changing visibility took two requests, so a failed second one left the new file live under the old visibility; PUT /api/dumps/:id/file takes isPrivate and applies both in one UPDATE, and it now broadcasts like any edit (it sent nothing, so other viewers never saw a new title). Notifications: one that arrived while the list was loading was dropped, then marked read by the read-all after the load, so it never showed; it's kept and merged in, once. Ranges: bytes=0-0,5-6 got a 416; several ranges, another unit or an unparseable header are ignored now and the whole file sent with a 200, as RFC 9110 allows — the old test asserted the 416.
All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 49s
All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 49s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -246,6 +246,87 @@ describe("useInfiniteScroll", () => {
|
||||
intersect(true);
|
||||
expect(onMore).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
// A load that fails re-enables the feed with the sentinel still in view: a
|
||||
// browser's new observer reports it at once, and without a pause that's a
|
||||
// request loop as fast as the request can fail.
|
||||
test("a sentinel that stays in view waits longer each time", () => {
|
||||
vi.useFakeTimers();
|
||||
const onMore = vi.fn();
|
||||
render(<Feed onMore={onMore} enabled />);
|
||||
intersect(true);
|
||||
expect(onMore).toHaveBeenCalledTimes(1);
|
||||
// Reported again right after each load, as a new observer does: how long
|
||||
// until the next one?
|
||||
const delays: number[] = [];
|
||||
for (let i = 0; i < 8; i++) {
|
||||
const before = onMore.mock.calls.length;
|
||||
intersect(true);
|
||||
let waited = 0;
|
||||
while (onMore.mock.calls.length === before) {
|
||||
act(() => vi.advanceTimersByTime(100));
|
||||
waited += 100;
|
||||
}
|
||||
delays.push(waited);
|
||||
}
|
||||
expect(delays).toEqual([1000, 2000, 4000, 8000, 16000, 30000, 30000, 30000]);
|
||||
});
|
||||
|
||||
test("re-rendering doesn't restart the wait", () => {
|
||||
vi.useFakeTimers();
|
||||
const onMore = vi.fn();
|
||||
const { rerender } = render(<Feed onMore={onMore} enabled />);
|
||||
intersect(true);
|
||||
intersect(true);
|
||||
act(() => vi.advanceTimersByTime(600));
|
||||
// A new onLoadMore (the feed's state changed) remakes the observer.
|
||||
rerender(<Feed onMore={() => onMore()} enabled />);
|
||||
intersect(true);
|
||||
act(() => vi.advanceTimersByTime(400));
|
||||
expect(onMore).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
test("leaving the view, or new items pushing it down, asks at once again", () => {
|
||||
vi.useFakeTimers();
|
||||
const onMore = vi.fn();
|
||||
render(<Feed onMore={onMore} enabled />);
|
||||
const at = (top: number) => {
|
||||
const obs = FakeIntersectionObserver.instances.at(-1)!;
|
||||
act(() =>
|
||||
obs.callback(
|
||||
[{ isIntersecting: true, boundingClientRect: { top } } as IntersectionObserverEntry],
|
||||
obs as unknown as IntersectionObserver,
|
||||
)
|
||||
);
|
||||
};
|
||||
at(500);
|
||||
at(500);
|
||||
expect(onMore).toHaveBeenCalledTimes(1); // waiting
|
||||
intersect(false);
|
||||
intersect(true);
|
||||
expect(onMore).toHaveBeenCalledTimes(2);
|
||||
at(500);
|
||||
at(900); // the page grew: that load worked
|
||||
expect(onMore).toHaveBeenCalledTimes(3);
|
||||
});
|
||||
|
||||
test("a pending retry is dropped when the feed is disabled or unmounted", () => {
|
||||
vi.useFakeTimers();
|
||||
const onMore = vi.fn();
|
||||
const { rerender, unmount } = render(<Feed onMore={onMore} enabled />);
|
||||
intersect(true);
|
||||
intersect(true);
|
||||
rerender(<Feed onMore={onMore} enabled={false} />);
|
||||
act(() => vi.advanceTimersByTime(60_000));
|
||||
expect(onMore).toHaveBeenCalledTimes(1);
|
||||
rerender(<Feed onMore={onMore} enabled />);
|
||||
intersect(true); // long overdue: at once
|
||||
expect(onMore).toHaveBeenCalledTimes(2);
|
||||
intersect(true);
|
||||
unmount();
|
||||
act(() => vi.advanceTimersByTime(60_000));
|
||||
expect(onMore).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe("useScrollLock", () => {
|
||||
|
||||
Reference in New Issue
Block a user