Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [EE] Fixed missing account-linking prompts during OAuth authorization and restored prompts when new optional providers are configured. [#1663](https://github.com/sourcebot-dev/sourcebot/pull/1663)
- Prevented browser performance instrumentation from breaking code views when `performance.measure()` returns no value. [#1665](https://github.com/sourcebot-dev/sourcebot/pull/1665)
- Added specific authentication error messages and recovery guidance shared by the login form and error page. [#1669](https://github.com/sourcebot-dev/sourcebot/pull/1669)
- Defaulted the home page to Ask when `EXPERIMENT_ASK_GH_ENABLED` is enabled and no preference is set. [#1672](https://github.com/sourcebot-dev/sourcebot/pull/1672)

## [5.1.13] - 2026-09-12

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { cookies } from "next/headers";
import { auth } from "@/auth";
import { HOME_VIEW_COOKIE_NAME } from "@/lib/constants";
import { HomeView } from "@/hooks/useHomeView";
import { getDefaultHomeView, resolveHomeView } from "@/lib/homeView";
import { getOrgAccountRequests } from "@/features/membership/actions";
import { isServiceError } from "@/lib/utils";
import { ServiceErrorException } from "@/lib/serviceError";
Expand All @@ -21,7 +21,11 @@ export const SIDEBAR_REPO_VISITS_LIMIT = 10;
export async function DefaultSidebar() {
const session = await auth();
const cookieStore = await cookies();
const homeView = (cookieStore.get(HOME_VIEW_COOKIE_NAME)?.value ?? "search") as HomeView;
const defaultHomeView = getDefaultHomeView(env.EXPERIMENT_ASK_GH_ENABLED === "true");
const homeView = resolveHomeView(
cookieStore.get(HOME_VIEW_COOKIE_NAME)?.value,
defaultHomeView,
);

// Chat history is part of the Ask experience; hide it when the deployment
// is not on a plan that includes Ask.
Expand Down
8 changes: 7 additions & 1 deletion packages/web/src/app/(app)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import { HOME_VIEW_COOKIE_NAME } from "@/lib/constants";
import { getDefaultHomeView, resolveHomeView } from "@/lib/homeView";
import { cookies } from "next/headers";
import { ChatLandingPage } from "./chat/chatLandingPage";
import SearchPage from "./search/page";
import { env } from "@sourcebot/shared";

interface Props {
searchParams: Promise<{ query?: string }>;
}

export default async function Home(props: Props) {
const cookieStore = await cookies();
const homeView = cookieStore.get(HOME_VIEW_COOKIE_NAME)?.value;
const defaultHomeView = getDefaultHomeView(env.EXPERIMENT_ASK_GH_ENABLED === "true");
const homeView = resolveHomeView(
cookieStore.get(HOME_VIEW_COOKIE_NAME)?.value,
defaultHomeView,
);
if (homeView === "ask") {
return <ChatLandingPage />;
}
Expand Down
10 changes: 8 additions & 2 deletions packages/web/src/app/(app)/settings/general/generalPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,17 @@ interface GeneralPageProps {
userName?: string;
userEmail?: string;
userImage?: string;
defaultHomeView: HomeView;
}

export function GeneralPage({ userName, userEmail, userImage }: GeneralPageProps) {
export function GeneralPage({
userName,
userEmail,
userImage,
defaultHomeView,
}: GeneralPageProps) {
const { theme: _theme, setTheme } = useTheme();
const [homeView, setHomeView] = useHomeView();
const [homeView, setHomeView] = useHomeView(defaultHomeView);
const [keymapType, setKeymapType] = useKeymapType();

const theme = useMemo(() => {
Expand Down
3 changes: 3 additions & 0 deletions packages/web/src/app/(app)/settings/general/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { authenticatedPage } from "@/middleware/authenticatedPage";
import { getDefaultHomeView } from "@/lib/homeView";
import { env } from "@sourcebot/shared";
import { GeneralPage } from "./generalPage";

export default authenticatedPage(async ({ user }) => {
Expand All @@ -7,6 +9,7 @@ export default authenticatedPage(async ({ user }) => {
userName={user.name ?? undefined}
userEmail={user.email ?? undefined}
userImage={user.image ?? undefined}
defaultHomeView={getDefaultHomeView(env.EXPERIMENT_ASK_GH_ENABLED === "true")}
/>
);
});
18 changes: 8 additions & 10 deletions packages/web/src/hooks/useHomeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,20 @@

import { useCallback, useState } from "react";
import { HOME_VIEW_COOKIE_NAME } from "@/lib/constants";
import { resolveHomeView, type HomeView } from "@/lib/homeView";

export type HomeView = "search" | "ask";
export type { HomeView } from "@/lib/homeView";

const COOKIE_NAME = HOME_VIEW_COOKIE_NAME;

function getHomeViewFromCookie(): HomeView {
function getHomeViewFromCookie(defaultHomeView: HomeView): HomeView {
if (typeof document === "undefined") {
return "search";
return defaultHomeView;
}
const cookies = document.cookie.split(';').map(c => c.trim());
const cookie = cookies.find(c => c.startsWith(`${COOKIE_NAME}=`));
if (!cookie) {
return "search";
}
const value = cookie.substring(`${COOKIE_NAME}=`.length);
return value === "ask" ? "ask" : "search";
const value = cookie?.substring(`${COOKIE_NAME}=`.length);
return resolveHomeView(value, defaultHomeView);
}

function setHomeViewCookie(value: HomeView) {
Expand All @@ -29,8 +27,8 @@ function setHomeViewCookie(value: HomeView) {
document.cookie = `${COOKIE_NAME}=${value}; expires=${expires.toUTCString()}; path=/; SameSite=Lax`;
}

export const useHomeView = (): [HomeView, (value: HomeView) => void] => {
const [homeView, setHomeViewState] = useState<HomeView>(getHomeViewFromCookie);
export const useHomeView = (defaultHomeView: HomeView = "search"): [HomeView, (value: HomeView) => void] => {
const [homeView, setHomeViewState] = useState<HomeView>(() => getHomeViewFromCookie(defaultHomeView));

const setHomeView = useCallback((value: HomeView) => {
setHomeViewState(value);
Expand Down
20 changes: 20 additions & 0 deletions packages/web/src/lib/homeView.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { describe, expect, test } from "vitest";
import { getDefaultHomeView, resolveHomeView } from "./homeView";

describe("home view selection", () => {
test("defaults to Ask when the experiment is enabled and no cookie is set", () => {
expect(resolveHomeView(undefined, getDefaultHomeView(true))).toBe("ask");
});

test("defaults to Code Search when the experiment is disabled and no cookie is set", () => {
expect(resolveHomeView(undefined, getDefaultHomeView(false))).toBe("search");
});

test("respects an explicit Code Search cookie when the experiment is enabled", () => {
expect(resolveHomeView("search", getDefaultHomeView(true))).toBe("search");
});

test("respects an explicit Ask cookie when the experiment is disabled", () => {
expect(resolveHomeView("ask", getDefaultHomeView(false))).toBe("ask");
});
});
16 changes: 16 additions & 0 deletions packages/web/src/lib/homeView.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export type HomeView = "search" | "ask";

export function getDefaultHomeView(isAskGhEnabled: boolean): HomeView {
return isAskGhEnabled ? "ask" : "search";
}

export function resolveHomeView(
cookieValue: string | undefined,
defaultHomeView: HomeView,
): HomeView {
if (cookieValue === "ask" || cookieValue === "search") {
return cookieValue;
}

return defaultHomeView;
}
Loading