🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(web): server-render title, description, canonical and favicon on auth pages (#17330)
Jannik Maierhöfer7e7d7af97031
diff --git a/web/src/components/design-system/LangfuseIcon/LangfuseIcon.tsx b/web/src/components/design-system/LangfuseIcon/LangfuseIcon.tsxindex 0513bed67a..106670d00e 100644--- a/web/src/components/design-system/LangfuseIcon/LangfuseIcon.tsx+++ b/web/src/components/design-system/LangfuseIcon/LangfuseIcon.tsx@@ -2,14 +2,19 @@ import { env } from "@/src/env.mjs";type LangfuseIconProps = {size?: 14 | 16 | 28 | 32 | 42;+ /** Pass `""` when a visible heading next to the icon already names it. */+ alt?: string;};-export const LangfuseIcon = ({ size = 32 }: LangfuseIconProps) => (+export const LangfuseIcon = ({+ size = 32,+ alt = "Langfuse",+}: LangfuseIconProps) => (// eslint-disable-next-line @next/next/no-img-element<imgsrc={`${env.NEXT_PUBLIC_BASE_PATH ?? ""}/icon.svg`}width={size}height={size}- alt="Langfuse Icon"+ alt={alt}/>);diff --git a/web/src/components/layouts/app-layout/variants/AuthenticatedLayout.tsx b/web/src/components/layouts/app-layout/variants/AuthenticatedLayout.tsxindex 043f0b060b..1f530fd2ef 100644--- a/web/src/components/layouts/app-layout/variants/AuthenticatedLayout.tsx+++ b/web/src/components/layouts/app-layout/variants/AuthenticatedLayout.tsx@@ -243,14 +243,24 @@ export function AuthenticatedLayout({<><Head><title>{metadata.title}</title>- <link rel="icon" type="image/svg+xml" href={metadata.faviconPath} /><link+ key="favicon-svg"+ rel="icon"+ type="image/svg+xml"+ href={metadata.faviconPath}+ />+ <link+ key="favicon-png"rel="icon"type="image/png"sizes="256x256"href={metadata.favicon256Path}/>- <link rel="apple-touch-icon" href={metadata.appleTouchIconPath} />+ <link+ key="apple-touch-icon"+ rel="apple-touch-icon"+ href={metadata.appleTouchIconPath}+ /></Head><SidebarPresenceProvider>diff --git a/web/src/components/layouts/default-head/DefaultHead.tsx b/web/src/components/layouts/default-head/DefaultHead.tsxnew file mode 100644index 0000000000..db02744c1c--- /dev/null+++ b/web/src/components/layouts/default-head/DefaultHead.tsx@@ -0,0 +1,63 @@+import Head from "next/head";+import { useRouter } from "next/router";+import { useLangfuseCloudRegion } from "@/src/features/organizations/hooks";+import { useLayoutMetadata } from "@/src/components/layouts/app-layout/hooks/useLayoutMetadata";+import { getPageMetadata } from "./getPageMetadata";++/**+ * Rendered in `_app` outside the layout, so it is part of every server+ * response — including the session-loading shell that is all a crawler gets.+ * Pages that render their own `<Head>` still win: `next/head` keeps the last+ * `<title>`, dedupes `<meta>` by name and `<link>` by `key`. The icon keys+ * match AuthenticatedLayout so its region-aware icons replace these.+ */+export function DefaultHead() {+ const { pathname } = useRouter();+ const { region } = useLangfuseCloudRegion();+ const { title, description, canonicalUrl } = getPageMetadata(+ pathname,+ region,+ );+ const icons = useLayoutMetadata(undefined, []);++ return (+ <Head>+ <title>{title}</title>+ <link+ key="favicon-svg"+ rel="icon"+ type="image/svg+xml"+ href={icons.faviconPath}+ />+ <link+ key="favicon-png"+ rel="icon"+ type="image/png"+ sizes="256x256"+ href={icons.favicon256Path}+ />+ <link+ key="apple-touch-icon"+ rel="apple-touch-icon"+ href={icons.appleTouchIconPath}+ />+ {/* Open Graph only where the copy is route-specific; a generic+ og:title would shadow the title unmapped pages set themselves. */}+ {description && (+ <>+ <meta name="description" content={description} />+ <meta property="og:title" content={title} />+ <meta property="og:description" content={description} />+ <meta property="og:type" content="website" />+ <meta property="og:site_name" content="Langfuse" />+ </>+ )}+ {canonicalUrl && (+ <>+ <link rel="canonical" href={canonicalUrl} />+ <meta property="og:url" content={canonicalUrl} />+ </>+ )}+ </Head>+ );+}diff --git a/web/src/components/layouts/default-head/getPageMetadata.ts b/web/src/components/layouts/default-head/getPageMetadata.tsnew file mode 100644index 0000000000..ab32ce9482--- /dev/null+++ b/web/src/components/layouts/default-head/getPageMetadata.ts@@ -0,0 +1,88 @@+import {+ type CloudRegionName,+ isRegionProduction,+} from "@/src/features/organizations/cloudRegions";++/**+ * Every region serves the same sign-in page, and the sign-in page is reached+ * with a `targetPath` query from shared traces. Google therefore sees many+ * URLs for one page and picks one of them; the canonical names that one page+ * so the choice is not left to the crawler.+ */+const CANONICAL_CLOUD_ORIGIN = "https://cloud.langfuse.com";++type PageMetadata = {+ title: string;+ description?: string;+ canonicalUrl?: string;+};++const cloudAuthPages: Record<string, PageMetadata> = {+ "/auth/sign-in": {+ title: "Sign in | Langfuse Cloud",+ description:+ "Sign in to Langfuse Cloud, the open source agent evals & observability platform. EU, US, Japan, and HIPAA data regions.",+ },+ "/auth/sign-up": {+ title: "Sign up | Langfuse Cloud",+ description:+ "Create a free Langfuse Cloud account. No credit card required. Trace, evaluate, and manage prompts for your LLM application.",+ },+};++const selfHostedAuthPages: Record<string, PageMetadata> = {+ "/auth/sign-in": {+ title: "Sign in | Langfuse",+ description:+ "Sign in to Langfuse, the open source agent evals & observability platform.",+ },+ "/auth/sign-up": {+ title: "Sign up | Langfuse",+ description: "Create a Langfuse account.",+ },+};++// Reached from e-mail links, not from search, so no region-specific copy.+// ResetPasswordPage swaps in "Set password" after hydration when the session+// shows the user has no password yet; that cannot be known from the route.+const passwordPages: Record<string, PageMetadata> = {+ "/auth/reset-password": {+ title: "Reset password | Langfuse",+ description: "Reset the password of your Langfuse account.",+ },+ "/auth/setup-password": {+ title: "Set password | Langfuse",+ description: "Set the password of your Langfuse account.",+ },+};++const defaultMetadata: PageMetadata = { title: "Langfuse" };++/**+ * Metadata that must be in the server-rendered HTML. Pages own their own+ * `<Head>`, but the auth pages render behind the session gate and never reach+ * the server response, so crawlers only see what is emitted here.+ *+ * `pathname` is the Next.js route (no query string), which is what makes the+ * canonical drop `?targetPath=`.+ */+export function getPageMetadata(+ pathname: string,+ region: CloudRegionName | undefined,+): PageMetadata {+ if (!region) {+ return (+ selfHostedAuthPages[pathname] ??+ passwordPages[pathname] ??+ defaultMetadata+ );+ }++ const metadata = cloudAuthPages[pathname] ?? passwordPages[pathname];+ if (!metadata) return defaultMetadata;++ // Staging and dev share the page but must not point Google at production.+ if (!isRegionProduction(region)) return metadata;++ return { ...metadata, canonicalUrl: `${CANONICAL_CLOUD_ORIGIN}${pathname}` };+}diff --git a/web/src/components/layouts/spinner.tsx b/web/src/components/layouts/spinner.tsxindex a810c843e5..6fa8b9e73d 100644--- a/web/src/components/layouts/spinner.tsx+++ b/web/src/components/layouts/spinner.tsx@@ -5,7 +5,7 @@ export function Spinner(props: { message: string }) {<div className="flex min-h-full flex-1 flex-col justify-center py-12 sm:px-6 lg:px-8"><div className="sm:mx-auto sm:w-full sm:max-w-md"><div className="mx-auto w-fit motion-safe:animate-spin">- <LangfuseIcon size={42} />+ <LangfuseIcon size={42} alt="" /></div><h2 className="text-primary mt-5 text-center text-2xl leading-9 font-bold tracking-tight">{props.message} ...diff --git a/web/src/features/auth-credentials/components/ResetPasswordPage.tsx b/web/src/features/auth-credentials/components/ResetPasswordPage.tsxindex 0247cfd30a..3b1ea8760f 100644--- a/web/src/features/auth-credentials/components/ResetPasswordPage.tsx+++ b/web/src/features/auth-credentials/components/ResetPasswordPage.tsx@@ -153,7 +153,7 @@ export function ResetPasswordPage({);const title = isSetMode ? "Set your password" : "Reset your password";- const pageTitle = isSetMode ? "Set Password" : "Reset Password";+ const pageTitle = isSetMode ? "Set password" : "Reset password";const submitLabel = isSetMode ? "Set password" : "Update Password";const successMessage = isSetMode? "Password set successfully. Redirecting ..."diff --git a/web/src/features/auth/SignInPage.tsx b/web/src/features/auth/SignInPage.tsxindex e81f879649..a652eb1cc9 100644--- a/web/src/features/auth/SignInPage.tsx+++ b/web/src/features/auth/SignInPage.tsx@@ -25,7 +25,6 @@ import {} from "react-icons/si";import { TbBrandAzure, TbBrandOauth } from "react-icons/tb";import { signIn, useSession } from "next-auth/react";-import Head from "next/head";import Link from "next/link";import { useState, useEffect, useRef } from "react";import { useForm } from "react-hook-form";@@ -772,25 +771,15 @@ export default function SignInPage({}if (previewAutoSignInEnabled && previewAutoSignInPending) {- return (- <>- <Head>- <title>Sign in | Langfuse</title>- </Head>- <Spinner message={`Signing in as ${PREVIEW_DEMO_USER_EMAIL}`} />- </>- );+ return <Spinner message={`Signing in as ${PREVIEW_DEMO_USER_EMAIL}`} />;}return (<>- <Head>- <title>Sign in | Langfuse</title>- </Head><div className="flex flex-1 flex-col py-6 sm:min-h-full sm:justify-center sm:px-6 sm:py-12 lg:px-8"><div className="sm:mx-auto sm:w-full sm:max-w-md"><div className="mx-auto w-fit">- <LangfuseIcon />+ <LangfuseIcon alt="" /></div><h2 className="text-primary mt-4 text-center text-2xl leading-9 font-bold tracking-tight">Sign in to your accountdiff --git a/web/src/features/auth/SignUpPage.tsx b/web/src/features/auth/SignUpPage.tsxindex bab9bc3421..8bf8b3c6fc 100644--- a/web/src/features/auth/SignUpPage.tsx+++ b/web/src/features/auth/SignUpPage.tsx@@ -11,7 +11,6 @@ import { Input } from "@/src/components/ui/input";import { signupSchema } from "@/src/features/auth/lib/signupSchema";import { zodResolver } from "@hookform/resolvers/zod";import { signIn } from "next-auth/react";-import Head from "next/head";import Link from "next/link";import { useForm } from "react-hook-form";import * as z from "zod";@@ -455,18 +454,10 @@ function SignupPageShell({ children }: { children: React.ReactNode }) {return (<>- <Head>- <title>Sign up | Langfuse</title>- <meta- name="description"- content="Create an account, no credit card required."- key="desc"- />- </Head><div className="flex flex-1 flex-col py-6 sm:min-h-full sm:justify-center sm:px-6 sm:py-12 lg:px-8"><div className="sm:mx-auto sm:w-full sm:max-w-md"><div className="mx-auto w-fit">- <LangfuseIcon />+ <LangfuseIcon alt="" /></div><h2 className="text-primary mt-4 text-center text-2xl leading-9 font-bold tracking-tight">Create new accountdiff --git a/web/src/features/v4-migration/V4MigrationStatusPage.clienttest.tsx b/web/src/features/v4-migration/V4MigrationStatusPage.clienttest.tsxindex 2cc535c225..a181157675 100644--- a/web/src/features/v4-migration/V4MigrationStatusPage.clienttest.tsx+++ b/web/src/features/v4-migration/V4MigrationStatusPage.clienttest.tsx@@ -218,7 +218,7 @@ describe("V4MigrationStatusPage", () => {expect(screen.getByRole("status")).toHaveClass("text-base", "leading-6");expect(screen.getByRole("status")).not.toHaveClass("text-2xl", "font-bold");expect(- screen.queryByRole("img", { name: "Langfuse Icon" }),+ screen.queryByRole("img", { name: "Langfuse" }),).not.toBeInTheDocument();});diff --git a/web/src/pages/_app.tsx b/web/src/pages/_app.tsxindex 5ccb0a77b2..5040b75e1a 100644--- a/web/src/pages/_app.tsx+++ b/web/src/pages/_app.tsx@@ -22,6 +22,7 @@ import { QueryParamProvider } from "use-query-params";import "@/src/styles/globals.css";import { AppLayout } from "@/src/components/layouts/app-layout";+import { DefaultHead } from "@/src/components/layouts/default-head/DefaultHead";import { useEffect, useRef } from "react";import { useRouter } from "next/router";@@ -184,6 +185,7 @@ const MyApp: AppType<{ session: Session | null }> = ({content="width=device-width, height=device-height, initial-scale=1, maximum-scale=1, user-scalable=no, shrink-to-fit=no, viewport-fit=cover"/></Head>+ <DefaultHead /><QueryParamProvideradapter={NextAdapterPagesWithReadyGuard}options={{ enableBatching: true }}