Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(client): recover snapshots that race thread creation #27617

Closedrolfilho(GitHub profile, opens in a new tab)wants to merge 3 commits intomain fromrefs/pull/27617/headopened View on GitHub

Showing 2 changed files with 102 additions and 13 deletions.

x
0 of 2 viewed, 2 left
91 additions and 7 deletionspackages/client-runtime/src/state/threads-sync.test.tsModified
View file
@@ -112,6 +112,7 @@
readonly latestLocalTurnOrdinal?: number | null;
readonly httpSnapshot?: ThreadSnapshotLoadResult;
+ readonly loadSnapshot?: () => Effect.Effect<ThreadSnapshotLoadResult>;
/** The test sends the completion marker itself instead of the fake server sending it first. */
readonly completionMarker?: boolean;
readonly resumeCache?: NonNullable<Parameters<typeof makeEnvironmentThreadState>[1]>;
@@ -179,11 +180,15 @@
const snapshotLoader = ThreadSnapshotLoader.ThreadSnapshotLoader.of({
load: (_prepared, threadId) =>
Ref.update(loaderCalls, (count) => count + 1).pipe(
- Effect.as(
- threadId === THREAD_ID
- ? (options?.httpSnapshot ??
- ({ _tag: "unavailable" } satisfies ThreadSnapshotLoadResult))
- : ({ _tag: "unavailable" } satisfies ThreadSnapshotLoadResult),
+ Effect.andThen(
+ options?.loadSnapshot ??
+ (() =>
+ Effect.succeed(
+ threadId === THREAD_ID
+ ? (options?.httpSnapshot ??
+ ({ _tag: "unavailable" } satisfies ThreadSnapshotLoadResult))
+ : ({ _tag: "unavailable" } satisfies ThreadSnapshotLoadResult),
+ )),
});