diff --git a/.changeset/private-notify-schedule.md b/.changeset/private-notify-schedule.md new file mode 100644 index 00000000000..1615ace12c5 --- /dev/null +++ b/.changeset/private-notify-schedule.md @@ -0,0 +1,5 @@ +--- +'@tanstack/query-core': major +--- + +Remove `notifyManager.schedule` from the public API. To schedule a callback through the notify manager, use `notifyManager.batchCalls(callback)()`. diff --git a/packages/query-core/src/__tests__/notifyManager.test-d.tsx b/packages/query-core/src/__tests__/notifyManager.test-d.tsx index 5ccfd3addcc..128d21b72b4 100644 --- a/packages/query-core/src/__tests__/notifyManager.test-d.tsx +++ b/packages/query-core/src/__tests__/notifyManager.test-d.tsx @@ -24,7 +24,6 @@ describe('notifyManager', () => { expectTypeOf>().toEqualTypeOf< | 'batch' | 'batchCalls' - | 'schedule' | 'setNotifyFunction' | 'setBatchNotifyFunction' | 'setScheduler' @@ -127,22 +126,6 @@ describe('notifyManager', () => { }) }) - describe('schedule', () => { - it('should only accept a callback taking no arguments', () => { - const localNotifyManager = createNotifyManager() - - expectTypeOf(localNotifyManager.schedule).parameters.toEqualTypeOf< - [callback: () => void] - >() - }) - - it('should return void', () => { - const localNotifyManager = createNotifyManager() - - expectTypeOf(localNotifyManager.schedule).returns.toEqualTypeOf() - }) - }) - describe('setNotifyFunction', () => { it('should only accept a function taking a callback', () => { const localNotifyManager = createNotifyManager() diff --git a/packages/query-core/src/__tests__/notifyManager.test.tsx b/packages/query-core/src/__tests__/notifyManager.test.tsx index 1bcfdfb1012..1e8e2a2b175 100644 --- a/packages/query-core/src/__tests__/notifyManager.test.tsx +++ b/packages/query-core/src/__tests__/notifyManager.test.tsx @@ -18,7 +18,7 @@ describe('notifyManager', () => { it('should notify in a microtask by default', async () => { const notifyManagerTest = createNotifyManager() const callbackSpy = vi.fn<() => void>() - notifyManagerTest.schedule(callbackSpy) + notifyManagerTest.batchCalls(callbackSpy)() expect(callbackSpy).not.toHaveBeenCalled() await Promise.resolve() expect(callbackSpy).toHaveBeenCalledWith() @@ -30,7 +30,7 @@ describe('notifyManager', () => { const callbackBatchLevel2Spy = vi .fn<() => void>() .mockImplementation(() => { - notifyManagerTest.schedule(callbackScheduleSpy) + notifyManagerTest.batchCalls(callbackScheduleSpy)() }) const callbackBatchLevel1Spy = vi .fn<() => void>() @@ -56,7 +56,7 @@ describe('notifyManager', () => { notifyManagerTest.setScheduler(customCallback) notifyManagerTest.setNotifyFunction(notifySpy) - notifyManagerTest.batch(() => notifyManagerTest.schedule(vi.fn)) + notifyManagerTest.batch(notifyManagerTest.batchCalls(vi.fn)) expect(customCallback).toHaveBeenCalledTimes(1) await vi.advanceTimersByTimeAsync(0) @@ -71,7 +71,7 @@ describe('notifyManager', () => { try { notifyManagerTest.batch(() => { - notifyManagerTest.schedule(vi.fn) + notifyManagerTest.batchCalls(vi.fn)() throw new Error('Foo') }) } catch {} @@ -89,8 +89,8 @@ describe('notifyManager', () => { notifyManagerTest.setBatchNotifyFunction(batchNotifySpy) notifyManagerTest.batch(() => { - notifyManagerTest.schedule(callbackSpy1) - notifyManagerTest.schedule(callbackSpy2) + notifyManagerTest.batchCalls(callbackSpy1)() + notifyManagerTest.batchCalls(callbackSpy2)() }) await vi.advanceTimersByTimeAsync(0) @@ -142,7 +142,7 @@ describe('notifyManager', () => { const notifyManagerCallbackSpy = vi.fn<() => void>() defaultScheduler(defaultSchedulerCallbackSpy) - notifyManager.schedule(notifyManagerCallbackSpy) + notifyManager.batchCalls(notifyManagerCallbackSpy)() expect(queueMicrotaskSpy).toHaveBeenCalledTimes(2) expect(queueMicrotaskSpy).toHaveBeenNthCalledWith( diff --git a/packages/query-core/src/notifyManager.ts b/packages/query-core/src/notifyManager.ts index 35a78aa5974..c7e74e4135d 100644 --- a/packages/query-core/src/notifyManager.ts +++ b/packages/query-core/src/notifyManager.ts @@ -92,11 +92,6 @@ export function createNotifyManager() { }) } }, - /** - * Schedules a function to be run on the next batch. - * By default, the batch runs in a microtask. Use `setScheduler` to change when it runs. - */ - schedule, /** * Use this method to set a custom notify function. * This can be used to for example wrap notifications with `React.act` while running tests. diff --git a/packages/svelte-query/src/useMutationState.svelte.ts b/packages/svelte-query/src/useMutationState.svelte.ts index aa0bbd70ed8..1eb382c89af 100644 --- a/packages/svelte-query/src/useMutationState.svelte.ts +++ b/packages/svelte-query/src/useMutationState.svelte.ts @@ -133,7 +133,6 @@ export function useMutationState< ) if (result.current !== nextResult) { result = nextResult - //notifyManager.schedule(onStoreChange) } }) }) */