TypeScript
fix(client): a thread opened before its shell loads still counts as opened (#25133)
Julius Marminge264969317c48
diff --git a/packages/client-runtime/src/state/threadVisits.test.ts b/packages/client-runtime/src/state/threadVisits.test.tsindex 98252a12a3a..3717f349f6b 100644--- a/packages/client-runtime/src/state/threadVisits.test.ts+++ b/packages/client-runtime/src/state/threadVisits.test.ts@@ -130,13 +130,18 @@ it("drops a pending visit when the thread is no longer viewed", () => {expect(t.visits).toHaveLength(1);});-it("records the open while the thread is shown before its shell arrives", () => {+it("sends the open with the first visit when the shell arrives after the thread is shown", () => {using t = setup("thread-shell-missing", null);t.mount();expect(claimThreadOpen(environmentId, t.ref.threadId, Date.UTC(2026, 0, 1))).toBe(false);+ expect(t.visits).toEqual([]);t.update({ updatedAt: at(10), lastVisitedAt: at(0), latestRun: null });- expect(t.visits).toEqual([{ threadId: t.ref.threadId, visitedAt: at(10) }]);+ expect(t.visits).toEqual([{ threadId: t.ref.threadId, visitedAt: at(10), opened: true }]);++ t.update({ updatedAt: at(10), lastVisitedAt: at(10) });+ vi.advanceTimersByTime(VISIT_DISPATCH_THROTTLE_MS);+ expect(t.visits).toHaveLength(1);});it("advances the watermark to a wake without waiting for the throttle", () => {diff --git a/packages/client-runtime/src/state/threadVisits.ts b/packages/client-runtime/src/state/threadVisits.tsindex 4185b982e18..ea063eed8e3 100644--- a/packages/client-runtime/src/state/threadVisits.ts+++ b/packages/client-runtime/src/state/threadVisits.ts@@ -56,7 +56,7 @@ export function createThreadVisitTracker(options: ThreadVisitTrackerOptions) {return Atom.make((get) => {const registry = get.registry;// Showing the thread is the open, whether or not its shell has arrived;- // the shell only decides whether the server hears about it now.+ // the shell only decides when the server hears about it.// Recorded even when the server cannot take opens, so recents follow// it. A palette pick already sent the open with its query.let openPending = claimThreadOpen(ref.environmentId, ref.threadId, Date.now());@@ -94,10 +94,6 @@ export function createThreadVisitTracker(options: ThreadVisitTrackerOptions) {const onShell = (shell: VisitedShell | null) => {clearTimer();- // Only a shell present when the thread is shown carries the open; one- // that arrives later is an ordinary visit.- const opened = openPending;- openPending = false;if (shell === null) return;const shellUpdatedAtMs = Date.parse(shell.updatedAt);@@ -110,7 +106,10 @@ export function createThreadVisitTracker(options: ThreadVisitTrackerOptions) {options.markLocalVisit?.(ref, visitedAt);return;}- if (opened) {+ // The open rides on the first visit the server hears, however late+ // the shell arrives, so it still counts toward search ranking.+ if (openPending) {+ openPending = false;dispatch(shell, visitedAt, true);return;}