nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: temporalio/ui
Pull request #81 (2021-09-13 20:08:15)

Update paginated.ts
Call the `onUpdate` callback _before_ recursing to the next page.


Patch:
diff --git a/src/lib/utilities/paginated.ts b/src/lib/utilities/paginated.ts
index 9865c593..618d8ed8 100644
--- a/src/lib/utilities/paginated.ts
+++ b/src/lib/utilities/paginated.ts
@@ -15,8 +15,8 @@ export const paginated = async <T extends WithNextPageToken>(
   const { nextPageToken, ...props } = await fn(token);
   const mergedProps = merge(previousProps, props);
 
+  if (typeof onUpdate === 'function') onUpdate(props, mergedProps);
   if (!nextPageToken) return mergedProps;
-  if (onUpdate) onUpdate(props, mergedProps);
 
   return paginated(fn, onUpdate, nextPageToken, mergedProps);
 };


Test patch:
diff --git a/src/lib/utilities/paginated.test.ts b/src/lib/utilities/paginated.test.ts
index ec515ad9..646f4b23 100644
--- a/src/lib/utilities/paginated.test.ts
+++ b/src/lib/utilities/paginated.test.ts
@@ -42,7 +42,7 @@ describe(paginated, () => {
   it('should collect incremental updates with an onUpdate callback', () => {
     const mockCallback = jest.fn((x) => x);
     return paginated((token) => fetchMock(token), mockCallback).then(() => {
-      expect(mockCallback.mock.calls.length).toBe(3);
+      expect(mockCallback.mock.calls.length).toBe(4);
     });
   });
 });