| author | |
| committer | |
| log | cf0988729b9a3695215b40bc5090ed5cebde810e |
| tree | 0baad9211b2a013fcb3cc4db9aef7e1250de7e75 |
| parent | 753ee8624109c92d55060573e22caa23be8d6ce9 |
| signature | Signed by SSH key SHA256:cOKiuRFOeSRxne6EWgHtdQQSlBxjOXm2hOCFnCdLQbQ |
The first debounced call in a burst set the channel to "waiting" even while a
request was mutating or refetching. When its timer fired, #enqueueDebouncedCall
saw "waiting" and started it concurrently, and the first request finishing
then marked the channel idle while the second was still in flight.
Assisted-by: claude-opus-5.5
Assisted-by: claude-opus-53 files changed, 38 insertions(+), 3 deletions(-)
readme.changes.md+2| ... | ... | @@ -12,6 +12,8 @@ |
| 12 | 12 | - resolve `runWithOptions` (and so `MutationButton`) setting `isPending` and |
| 13 | 13 | disabling controls for debounced mutations, and leaving a pending delay from |
| 14 | 14 | an earlier `run` to set `isPending` later |
| 15 | - resolve a debounced call made during an in-flight request running alongside | |
| 16 | it, which let the first request mark the mutation idle mid-flight | |
| 15 | 17 | |
| 16 | 18 | ## v3.0.2 |
| 17 | 19 |
src/mutation.ts+5-3| ... | ... | @@ -817,9 +817,11 @@ export class BlockingMutation< |
| 817 | 817 | shouldCallGlobalHandler, |
| 818 | 818 | }; |
| 819 | 819 | |
| 820 | // Set status to waiting | |
| 821 | channel.status = "waiting"; | |
| 822 | this.#notify(channel, "waiting"); | |
| 820 | // An in-flight request picks the call up when it finishes | |
| 821 | if (channel.status === "idle") { | |
| 822 | channel.status = "waiting"; | |
| 823 | this.#notify(channel, "waiting"); | |
| 824 | } | |
| 823 | 825 | } else { |
| 824 | 826 | // Subsequent debounced call - update state |
| 825 | 827 | channel.pendingDebounced.args = args; |
test/ordering.test.ts+31| ... | ... | @@ -491,3 +491,34 @@ test("a synchronous throw from mutate fails the call without wedging the channel |
| 491 | 491 | assertEquals(errorMessages.map((e) => e.message), ["Could not test: Sync failure"]); |
| 492 | 492 | assertEquals(successMessages, ["Completed 2"]); |
| 493 | 493 | }); |
| 494 | ||
| 495 | test("a debounced call made during an in-flight request waits for it", async () => { | |
| 496 | vi.useFakeTimers(); | |
| 497 | const { client } = createTestMutationClient(); | |
| 498 | const calls: string[] = []; | |
| 499 | ||
| 500 | const mutTest = client.define({ | |
| 501 | id: "test-12", | |
| 502 | mutate: async (id: number) => { | |
| 503 | calls.push(`start-${id}`); | |
| 504 | await delay(100); | |
| 505 | calls.push(`end-${id}`); | |
| 506 | return `result-${id}`; | |
| 507 | }, | |
| 508 | describe: "test", | |
| 509 | describeResult: null, | |
| 510 | optimistic: () => {}, | |
| 511 | refetchOnSuccess: false, | |
| 512 | debounceMs: 10, | |
| 513 | }); | |
| 514 | mutTest.subscribe(mutTest.key([1]), ({ status }) => { | |
| 515 | if (status === "idle") calls.push("idle"); | |
| 516 | }); | |
| 517 | ||
| 518 | mutTest.run(1); | |
| 519 | await vi.advanceTimersByTimeAsync(50); | |
| 520 | mutTest.run(2); | |
| 521 | await vi.advanceTimersByTimeAsync(500); | |
| 522 | ||
| 523 | assertEquals(calls, ["start-1", "end-1", "start-2", "end-2", "idle"]); | |
| 524 | }); |