Skip to content

Commit fde221d

Browse files
saphidclaude
andcommitted
test(web): follow main's reactivity import and cover the overtaken-list retry
Main moved Effect reactivity to effect/reactivity, so the sync test now imports it from there. It also checks that main's retry after an event overtakes the first list still runs, and completes, alongside the waiting guard. The guard makes the old waiting check in that retry redundant. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 9004e8c commit fde221d

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

‎apps/web/src/components/preview/previewSessionSync.test.ts‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
type ScopedThreadRef,
77
} from "@t3tools/contracts";
88
import * as Cause from "effect/Cause";
9-
import { AsyncResult, Atom } from "effect/unstable/reactivity";
9+
import { AsyncResult, Atom } from "effect/reactivity";
1010
import { act, createElement } from "react";
1111
import { create, type ReactTestRenderer } from "react-test-renderer";
1212
import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
@@ -27,7 +27,7 @@ const harness = vi.hoisted(() => ({
2727
}));
2828

2929
vi.mock("~/state/preview", async () => {
30-
const { AsyncResult, Atom } = await import("effect/unstable/reactivity");
30+
const { AsyncResult, Atom } = await import("effect/reactivity");
3131
return {
3232
previewEnvironment: {
3333
list: (target: { input: { threadId: string } }) => {
@@ -177,7 +177,7 @@ describe("native preview session synchronization", () => {
177177
expect(readThreadPreviewState(ref).desktopOverlay?.canGoBack).toBe(true);
178178
});
179179

180-
it("retains newer event state when an older list response completes", async () => {
180+
it("retains newer event state when an older list response completes, then retries the list", async () => {
181181
const atom = listAtom();
182182
await mount();
183183
const snapshot = result(2, ["opened"]).sessions[0]!;
@@ -194,9 +194,17 @@ describe("native preview session synchronization", () => {
194194
createdAt: snapshot.updatedAt,
195195
}),
196196
);
197-
appAtomRegistry.set(atom, AsyncResult.success(result(1, [])));
197+
await act(async () => appAtomRegistry.set(atom, AsyncResult.success(result(1, []))));
198198
expect(readThreadPreviewState(ref).activeTabId).toBe("opened");
199199
expect(readThreadPreviewState(ref).serverRevision).toBe(2);
200+
expect(readThreadPreviewState(ref).listLoaded).toBe(false);
201+
// The overtaken list is not a baseline, so the hook asks again; its
202+
// waiting state must not reconcile, and the fresh answer completes it.
203+
expect(harness.lists.get(ref.threadId)?.box.requests).toBe(2);
204+
expect(readThreadPreviewState(ref).activeTabId).toBe("opened");
205+
appAtomRegistry.set(atom, AsyncResult.success(result(2, ["opened"])));
206+
expect(readThreadPreviewState(ref).listLoaded).toBe(true);
207+
expect(readThreadPreviewState(ref).activeTabId).toBe("opened");
200208
});
201209

202210
it("keeps the local snapshot on a completed failure and reconciles a later success", async () => {

‎apps/web/src/components/preview/usePreviewSession.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const previewSessionSyncAtom = Atom.family((threadKey: string) => {
4444
const reconcileSessions = (result: Atom.Type<typeof sessionsAtom>) => {
4545
if (result.waiting || !AsyncResult.isSuccess(result)) return;
4646
reconcilePreviewServerSessions(threadRef, result.value);
47-
if (!result.waiting && !readThreadPreviewState(threadRef).listLoaded) {
47+
if (!readThreadPreviewState(threadRef).listLoaded) {
4848
// An event overtook the first list. Retry the authoritative baseline;
4949
// do not declare a partial event-only index ready for surface cleanup.
5050
queueMicrotask(() => {

0 commit comments

Comments
 (0)