Skip to content

Commit

Permalink
Remove unstable_next from useLoadMoreFunction
Browse files Browse the repository at this point in the history
Reviewed By: jstejada

Differential Revision: D24954056

fbshipit-source-id: 6c2d92e3f47c57d3fc5b4bd44214805abea0ca65
  • Loading branch information
tyao1 authored and facebook-github-bot committed Nov 16, 2020
1 parent 95606c5 commit 3242c58
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -685,22 +685,10 @@ describe('useBlockingPaginationFragment', () => {
});

describe('pagination', () => {
let runScheduledCallback = () => {};
let release;

beforeEach(() => {
jest.resetModules();
jest.doMock('scheduler', () => {
const original = jest.requireActual('scheduler/unstable_mock');
return {
...original,
unstable_next: cb => {
runScheduledCallback = () => {
original.unstable_next(cb);
};
},
};
});

release = jest.fn();
environment.retain.mockImplementation((...args) => {
Expand All @@ -710,10 +698,6 @@ describe('useBlockingPaginationFragment', () => {
});
});

afterEach(() => {
jest.dontMock('scheduler');
});

function expectRequestIsInFlight(expected) {
expect(environment.execute).toBeCalledTimes(expected.requestCount);
expect(
Expand Down Expand Up @@ -838,11 +822,14 @@ describe('useBlockingPaginationFragment', () => {
gqlPaginationQuery,
});

expect(callback).toBeCalledTimes(0);

TestRenderer.act(() => {
loadNext(1, {onComplete: callback});
});

expect(environment.execute).toBeCalledTimes(1);
expect(callback).toBeCalledTimes(0);
expect(callback).toBeCalledTimes(1);
expect(renderSpy).toBeCalledTimes(0);
});

Expand Down Expand Up @@ -870,7 +857,7 @@ describe('useBlockingPaginationFragment', () => {
loadNext(1, {onComplete: callback});
});
expect(environment.execute).toBeCalledTimes(0);
expect(callback).toBeCalledTimes(0);
expect(callback).toBeCalledTimes(1);
expect(renderSpy).toBeCalledTimes(0);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -740,22 +740,10 @@ describe('usePaginationFragment', () => {
});

describe('pagination', () => {
let runScheduledCallback = () => {};
let release;

beforeEach(() => {
jest.resetModules();
jest.doMock('scheduler', () => {
const original = jest.requireActual('scheduler/unstable_mock');
return {
...original,
unstable_next: cb => {
runScheduledCallback = () => {
original.unstable_next(cb);
};
},
};
});

release = jest.fn();
environment.retain.mockImplementation((...args) => {
Expand All @@ -765,10 +753,6 @@ describe('usePaginationFragment', () => {
});
});

afterEach(() => {
jest.dontMock('scheduler');
});

function expectRequestIsInFlight(expected) {
expect(environment.execute).toBeCalledTimes(expected.requestCount);
expect(
Expand Down Expand Up @@ -890,6 +874,8 @@ describe('usePaginationFragment', () => {
TestRenderer.act(() => {
loadNext(1, {onComplete: callback});
});
expect(callback).toBeCalledTimes(0);

const paginationVariables = {
id: '1',
after: 'cursor:1',
Expand All @@ -912,7 +898,7 @@ describe('usePaginationFragment', () => {
loadNext(1, {onComplete: callback});
});
expect(environment.execute).toBeCalledTimes(1);
expect(callback).toBeCalledTimes(0);
expect(callback).toBeCalledTimes(1);
expect(renderSpy).toBeCalledTimes(0);
});

Expand Down Expand Up @@ -943,7 +929,7 @@ describe('usePaginationFragment', () => {
loadNext(1, {onComplete: callback});
});
expect(environment.execute).toBeCalledTimes(0);
expect(callback).toBeCalledTimes(0);
expect(callback).toBeCalledTimes(1);
expect(renderSpy).toBeCalledTimes(0);
});

Expand Down
7 changes: 1 addition & 6 deletions packages/relay-experimental/useLoadMoreFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@

'use strict';

// flowlint-next-line untyped-import:off
const Scheduler = require('scheduler');

const getPaginationVariables = require('./getPaginationVariables');
const getValueAtPath = require('./getValueAtPath');
const invariant = require('invariant');
Expand Down Expand Up @@ -175,9 +172,7 @@ function useLoadMoreFunction<TQuery: OperationType>(
}

if (onComplete) {
// We make sure to always call onComplete asynchronously to prevent
// accidental loops in product code.
Scheduler.unstable_next(() => onComplete(null));
onComplete(null);
}
return {dispose: () => {}};
}
Expand Down

0 comments on commit 3242c58

Please sign in to comment.