| author | |
| committer | |
| log | e974dee2fb62fa115dc200354f85ff69145c36c7 |
| tree | c8c6ff8378be22d4c82ac6ee72805e87ba2e517d |
| parent | 7d66362e0dbb074ed16b613b8bab554f5b231875 |
| signature | Signed by SSH key SHA256:cOKiuRFOeSRxne6EWgHtdQQSlBxjOXm2hOCFnCdLQbQ |
#executeNext marked the channel "mutating" and then chained .then() onto the
return value of mutate. A mutate (or useAsyncCallback callback) that threw
synchronously escaped to the caller instead, leaving the channel "mutating"
forever: isMutating and isDisabled stuck true and later calls queued behind
it.
Assisted-by: claude-opus-5.5
Assisted-by: claude-opus-53 files changed, 30 insertions(+), 1 deletions(-)
readme.changes.md+2| ... | @@ -5,6 +5,8 @@ | ... | @@ -5,6 +5,8 @@ |
| 5 | ### bugfixes | 5 | ### bugfixes |
| 6 | 6 | ||
| 7 | - resolve calls made while a failed mutation refetches never running | 7 | - resolve calls made while a failed mutation refetches never running |
| 8 | - resolve a synchronous throw from `mutate` escaping to the caller and leaving | ||
| 9 | the mutation stuck in its mutating state | ||
| 8 | 10 | ||
| 9 | ## v3.0.2 | 11 | ## v3.0.2 |
| 10 | 12 |
src/mutation.ts+1-1| ... | @@ -599,7 +599,7 @@ export class BlockingMutation< | ... | @@ -599,7 +599,7 @@ export class BlockingMutation< |
| 599 | channel.status = "mutating"; | 599 | channel.status = "mutating"; |
| 600 | this.#notify(channel, "mutating"); | 600 | this.#notify(channel, "mutating"); |
| 601 | 601 | ||
| 602 | this.#options.mutate.call(context, ...args).then((result) => { | 602 | new Promise<Result>((resolve) => resolve(this.#options.mutate.call(context, ...args))).then((result) => { |
| 603 | // remove rollbacks and apply optimistic success handlers | 603 | // remove rollbacks and apply optimistic success handlers |
| 604 | channel.rollbacks.splice(0, item.rollbacks); | 604 | channel.rollbacks.splice(0, item.rollbacks); |
| 605 | onSuccess.forEach((cb) => cb(result)); | 605 | onSuccess.forEach((cb) => cb(result)); |
test/ordering.test.ts+27| ... | @@ -464,3 +464,30 @@ test("a call made during the post-failure refetch runs once the refetch settles" | ... | @@ -464,3 +464,30 @@ test("a call made during the post-failure refetch runs once the refetch settles" |
| 464 | assertEquals(calls, ["mutate-1", "mutate-2"]); | 464 | assertEquals(calls, ["mutate-1", "mutate-2"]); |
| 465 | assertEquals(successMessages, ["Completed 2"]); | 465 | assertEquals(successMessages, ["Completed 2"]); |
| 466 | }); | 466 | }); |
| 467 | |||
| 468 | test("a synchronous throw from mutate fails the call without wedging the channel", async () => { | ||
| 469 | vi.useFakeTimers(); | ||
| 470 | const { client, errorMessages, successMessages } = createTestMutationClient(); | ||
| 471 | const calls: string[] = []; | ||
| 472 | |||
| 473 | const mutTest = client.define({ | ||
| 474 | id: "test-11", | ||
| 475 | mutate: (id: number) => { | ||
| 476 | calls.push(`mutate-${id}`); | ||
| 477 | if (id === 1) throw new Error("Sync failure"); | ||
| 478 | return Promise.resolve(`result-${id}`); | ||
| 479 | }, | ||
| 480 | describe: "test", | ||
| 481 | describeResult: (ctx) => `Completed ${ctx.args[0]}`, | ||
| 482 | optimistic: () => {}, | ||
| 483 | }); | ||
| 484 | |||
| 485 | mutTest.run(1); | ||
| 486 | await vi.advanceTimersByTimeAsync(0); | ||
| 487 | mutTest.run(2); | ||
| 488 | await vi.advanceTimersByTimeAsync(0); | ||
| 489 | |||
| 490 | assertEquals(calls, ["mutate-1", "mutate-2"]); | ||
| 491 | assertEquals(errorMessages.map((e) => e.message), ["Could not test: Sync failure"]); | ||
| 492 | assertEquals(successMessages, ["Completed 2"]); | ||
| 493 | }); |