fix(home): stop silent rectification open after login (BUG-599)
Bare `/` was treating the latest history session as active, so a returning account could auto-open a failed rectification Case and left-align the starter home. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -8,8 +8,62 @@
|
||||
* settled, or when the prepare budget runs out — never with a spinner inside.
|
||||
*/
|
||||
|
||||
import { parseSessionUrlQuery } from "./chat-session-url.ts";
|
||||
|
||||
export type BootstrapPhase = "account" | "prepare";
|
||||
|
||||
export type LandingSession = Readonly<{
|
||||
id: string;
|
||||
sessionType: string;
|
||||
messages: readonly unknown[];
|
||||
}>;
|
||||
|
||||
export type LandingUrlAction = "keep" | "replace-selected" | "replace-clear" | "none";
|
||||
|
||||
/**
|
||||
* A rectification Case is opened only when the address bar names that session
|
||||
* (`?c=`), including refresh and a login return that restored the URL. Bare `/`
|
||||
* after login must not open the latest history item in the background.
|
||||
*/
|
||||
export function shouldAutoOpenRectificationSession(input: {
|
||||
readonly sessionType: string | undefined;
|
||||
readonly sessionId: string | undefined;
|
||||
readonly search: string;
|
||||
}): boolean {
|
||||
if (input.sessionType !== "birth_time_rectification" || !input.sessionId) return false;
|
||||
return parseSessionUrlQuery(input.search).sessionId === input.sessionId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default `/` landing prefers an empty consultation so the starter home can
|
||||
* center. Deep links and login-return URLs keep the requested session.
|
||||
*/
|
||||
export function resolveStarterHomeLandingSessionId(
|
||||
sessions: readonly LandingSession[],
|
||||
selectedId: string,
|
||||
urlAction: LandingUrlAction,
|
||||
): string {
|
||||
if (urlAction === "keep" || urlAction === "replace-selected") return selectedId;
|
||||
const selected = sessions.find((session) => session.id === selectedId);
|
||||
if (selected?.sessionType !== "birth_time_rectification") return selectedId;
|
||||
const emptyConsultation = sessions.find(
|
||||
(session) => session.sessionType === "consultation" && session.messages.length === 0,
|
||||
);
|
||||
if (emptyConsultation) return emptyConsultation.id;
|
||||
const anyConsultation = sessions.find((session) => session.sessionType === "consultation");
|
||||
return anyConsultation?.id ?? selectedId;
|
||||
}
|
||||
|
||||
export function starterHomeLandingNeedsConsultation(
|
||||
sessions: readonly LandingSession[],
|
||||
landingId: string,
|
||||
urlAction: LandingUrlAction,
|
||||
): boolean {
|
||||
if (urlAction === "keep" || urlAction === "replace-selected") return false;
|
||||
const landing = sessions.find((session) => session.id === landingId);
|
||||
return !landing || landing.sessionType === "birth_time_rectification";
|
||||
}
|
||||
|
||||
export const BOOTSTRAP_PREPARE_TIMEOUT_MS = 4000;
|
||||
export const SESSION_PREFETCH_COUNT = 5;
|
||||
|
||||
@@ -19,7 +73,7 @@ export type BootstrapPrepareState = Readonly<{
|
||||
dailyStarlanguageApplicable: boolean;
|
||||
dailyStarlanguageSettled: boolean;
|
||||
entrySummarySettled: boolean;
|
||||
/** The selected session is a rectification session: its Case must be open and hydrated before the reveal. */
|
||||
/** A URL-named rectification session must be opened and hydrated before reveal. */
|
||||
rectificationApplicable?: boolean;
|
||||
rectificationSettled?: boolean;
|
||||
}>;
|
||||
|
||||
Reference in New Issue
Block a user