| author | |
| committer | |
| log | 7d66362e0dbb074ed16b613b8bab554f5b231875 |
| tree | dd6085a9ac1bb54362b5e788ceb1009023eee15b |
| parent | 02fca8a6248c2898025748f41c9bf5252094fd9e |
| signature | Signed by SSH key SHA256:cOKiuRFOeSRxne6EWgHtdQQSlBxjOXm2hOCFnCdLQbQ |
After a failed mutation, the channel sat in "refetching" while its refetch
callbacks ran, then went straight to idle without draining its queue. A call
made during that window was queued but never executed until some later call
happened to drain the channel, so it ran late against stale state or was
dropped with the channel.
Assisted-by: claude-opus-5.5
Assisted-by: claude-opus-54 files changed, 37 insertions(+), 2 deletions(-)
jsr.json+1-1| ... | @@ -1,6 +1,6 @@ | ... | @@ -1,6 +1,6 @@ |
| 1 | { | 1 | { |
| 2 | "name": "@clo/react-mutation", | 2 | "name": "@clo/react-mutation", |
| 3 | "version": "3.0.2", | 3 | "version": "3.0.3", |
| 4 | "exports": { | 4 | "exports": { |
| 5 | ".": "./src/mod.ts", | 5 | ".": "./src/mod.ts", |
| 6 | "./tanstack-query": "./src/tanstack-query.ts", | 6 | "./tanstack-query": "./src/tanstack-query.ts", |
readme.changes.md+6| ... | @@ -1,5 +1,11 @@ | ... | @@ -1,5 +1,11 @@ |
| 1 | # notable changes in React Mutation | 1 | # notable changes in React Mutation |
| 2 | 2 | ||
| 3 | ## v3.0.3 | ||
| 4 | |||
| 5 | ### bugfixes | ||
| 6 | |||
| 7 | - resolve calls made while a failed mutation refetches never running | ||
| 8 | |||
| 3 | ## v3.0.2 | 9 | ## v3.0.2 |
| 4 | 10 | ||
| 5 | ### bugfixes | 11 | ### bugfixes |
src/mutation.ts+1-1| ... | @@ -662,7 +662,7 @@ export class BlockingMutation< | ... | @@ -662,7 +662,7 @@ export class BlockingMutation< |
| 662 | } | 662 | } |
| 663 | }); | 663 | }); |
| 664 | }).finally(() => { | 664 | }).finally(() => { |
| 665 | this.#setIdle(key, channel); | 665 | this.#executeNext(key, channel); |
| 666 | }); | 666 | }); |
| 667 | 667 | ||
| 668 | reject(wrappedError); | 668 | reject(wrappedError); |
test/ordering.test.ts+29| ... | @@ -435,3 +435,32 @@ test("optimistic update with no describeResult: no success message", async () => | ... | @@ -435,3 +435,32 @@ test("optimistic update with no describeResult: no success message", async () => |
| 435 | assertEquals(successMessages, [], "No success message when describeResult is null"); | 435 | assertEquals(successMessages, [], "No success message when describeResult is null"); |
| 436 | assertEquals(calls.includes("success"), true, "onSuccess callback still called"); | 436 | assertEquals(calls.includes("success"), true, "onSuccess callback still called"); |
| 437 | }); | 437 | }); |
| 438 | |||
| 439 | test("a call made during the post-failure refetch runs once the refetch settles", async () => { | ||
| 440 | vi.useFakeTimers(); | ||
| 441 | const { client, successMessages } = createTestMutationClient(); | ||
| 442 | const calls: string[] = []; | ||
| 443 | |||
| 444 | const mutTest = client.define({ | ||
| 445 | id: "test-10", | ||
| 446 | mutate: async (id: number) => { | ||
| 447 | calls.push(`mutate-${id}`); | ||
| 448 | await delay(100); | ||
| 449 | if (id === 1) throw new Error("First failed"); | ||
| 450 | return `result-${id}`; | ||
| 451 | }, | ||
| 452 | describe: "test", | ||
| 453 | describeResult: (ctx) => `Completed ${ctx.args[0]}`, | ||
| 454 | optimistic: ({ onRefetch }) => { | ||
| 455 | onRefetch(() => delay(100)); | ||
| 456 | }, | ||
| 457 | }); | ||
| 458 | |||
| 459 | mutTest.run(1); | ||
| 460 | await vi.advanceTimersByTimeAsync(150); | ||
| 461 | mutTest.run(2); | ||
| 462 | await vi.advanceTimersByTimeAsync(500); | ||
| 463 | |||
| 464 | assertEquals(calls, ["mutate-1", "mutate-2"]); | ||
| 465 | assertEquals(successMessages, ["Completed 2"]); | ||
| 466 | }); |