fix(chat): keep page.tsx at the 1951-line freeze after lookup wiring
Move BUG-705 bootstrap selection + session lookup into resolveLookupBootstrap so Home only awaits once. The 1951 cap in chart-view-route.test.ts is unchanged.
This commit is contained in:
@@ -125,9 +125,6 @@ import { writeChatSession } from "@/lib/chat-session-write-contract";
|
||||
import {
|
||||
SESSION_MISSING_NOTICE,
|
||||
clearLoginSessionReturn,
|
||||
parseSessionUrlQuery,
|
||||
readLoginSessionReturn,
|
||||
resolveBootstrapSessionSelection,
|
||||
writeSessionUrl,
|
||||
} from "@/lib/chat-session-url";
|
||||
import { consultationReportMarkdown } from "@/lib/consultation-report-export";
|
||||
@@ -994,20 +991,10 @@ export default function Home() {
|
||||
}
|
||||
|
||||
if (controller.signal.aborted) return;
|
||||
const listedSelection = resolveBootstrapSessionSelection({
|
||||
listedIds: nextSessions.map((session) => session.id),
|
||||
defaultSessionId: nextSessions[0].id,
|
||||
search: window.location.search,
|
||||
storedReturnId: readLoginSessionReturn(),
|
||||
});
|
||||
const lookedUp = await resolveLookupBootstrap({
|
||||
selection: listedSelection,
|
||||
sessions: nextSessions,
|
||||
defaultSessionId: nextSessions[0].id,
|
||||
catalog: nextModelCatalog,
|
||||
signal: controller.signal,
|
||||
sessions: nextSessions, catalog: nextModelCatalog,
|
||||
defaultSessionId: nextSessions[0].id, signal: controller.signal,
|
||||
});
|
||||
if (controller.signal.aborted) return;
|
||||
nextSessions = lookedUp.sessions;
|
||||
const bootstrapSelection = lookedUp.selection;
|
||||
let landingSessionId = resolveStarterHomeLandingSessionId(
|
||||
|
||||
@@ -2,6 +2,8 @@ import { writeChatSession } from "@/lib/chat-session-write-contract";
|
||||
import {
|
||||
bootstrapSelectionFromLookup,
|
||||
persistLoginSessionReturn,
|
||||
readLoginSessionReturn,
|
||||
resolveBootstrapSessionSelection,
|
||||
SESSION_LOOKUP_FAILED_NOTICE,
|
||||
type BootstrapSessionSelection,
|
||||
} from "@/lib/chat-session-url";
|
||||
@@ -496,8 +498,14 @@ export async function lookupSessionById(
|
||||
return { status: "found", session };
|
||||
}
|
||||
|
||||
function throwIfAborted(signal?: AbortSignal) {
|
||||
if (!signal?.aborted) return;
|
||||
const error = new Error("Aborted");
|
||||
error.name = "AbortError";
|
||||
throw error;
|
||||
}
|
||||
|
||||
export async function resolveLookupBootstrap(input: {
|
||||
selection: BootstrapSessionSelection;
|
||||
sessions: ChatSession[];
|
||||
defaultSessionId: string;
|
||||
catalog: PublicLanguageModelCatalog | null;
|
||||
@@ -507,10 +515,18 @@ export async function resolveLookupBootstrap(input: {
|
||||
sessions: ChatSession[];
|
||||
notice: string | null;
|
||||
}> {
|
||||
if (input.selection.urlAction !== "lookup") {
|
||||
return { selection: input.selection, sessions: input.sessions, notice: null };
|
||||
throwIfAborted(input.signal);
|
||||
const selection = resolveBootstrapSessionSelection({
|
||||
listedIds: input.sessions.map((session) => session.id),
|
||||
defaultSessionId: input.defaultSessionId,
|
||||
search: window.location.search,
|
||||
storedReturnId: readLoginSessionReturn(),
|
||||
});
|
||||
if (selection.urlAction !== "lookup") {
|
||||
return { selection, sessions: input.sessions, notice: null };
|
||||
}
|
||||
const looked = await lookupSessionById(input.selection.sessionId, input.catalog, input.signal);
|
||||
const looked = await lookupSessionById(selection.sessionId, input.catalog, input.signal);
|
||||
throwIfAborted(input.signal);
|
||||
if (looked.status === "found") {
|
||||
return {
|
||||
selection: bootstrapSelectionFromLookup("found", looked.session.id, input.defaultSessionId),
|
||||
@@ -520,13 +536,13 @@ export async function resolveLookupBootstrap(input: {
|
||||
}
|
||||
if (looked.status === "missing") {
|
||||
return {
|
||||
selection: bootstrapSelectionFromLookup("missing", input.selection.sessionId, input.defaultSessionId),
|
||||
selection: bootstrapSelectionFromLookup("missing", selection.sessionId, input.defaultSessionId),
|
||||
sessions: input.sessions,
|
||||
notice: null,
|
||||
};
|
||||
}
|
||||
return {
|
||||
selection: bootstrapSelectionFromLookup("unavailable", input.selection.sessionId, input.defaultSessionId),
|
||||
selection: bootstrapSelectionFromLookup("unavailable", selection.sessionId, input.defaultSessionId),
|
||||
sessions: input.sessions,
|
||||
notice: SESSION_LOOKUP_FAILED_NOTICE,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user