Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat(preview): add a top strip linking previews back to their PR (#15580)

Trang Nguyena6f8793518b7
diff --git a/.agents/skills/langfuse-previews/SKILL.md b/.agents/skills/langfuse-previews/SKILL.md
index dc2a409b2c..18203e3793 100644
--- a/.agents/skills/langfuse-previews/SKILL.md
+++ b/.agents/skills/langfuse-previews/SKILL.md
@@ -40,6 +40,8 @@ Pushing updates it; closing the PR tears it down.
truth). The demo project's shared seed identity is `[email protected]` /
`password`, with API keys `pk-lf-1234567890` / `sk-lf-1234567890` — shared and
synthetic, so never treat a preview as private.
+- **Know where you are** — every preview page shows a top strip linking back
+ to the PR, with the author and when the preview content last changed.
- **Update** — push to the PR; it rebuilds and rolls to the new image (~5 min,
**same URL, data preserved**). A brief `ImagePullBackOff` during the rebuild
is normal and self-heals.
diff --git a/.github/workflows/preview-build.yml b/.github/workflows/preview-build.yml
index 43c33ffde1..14720b963a 100644
--- a/.github/workflows/preview-build.yml
+++ b/.github/workflows/preview-build.yml
@@ -201,6 +201,12 @@ jobs:
DOCKERFILE: ${{ matrix.dockerfile }}
# Static, workflow-defined literal (per-target flags) — no user input.
EXTRA_BUILD_ARGS: ${{ matrix.extra_build_args }}
+ TARGET: ${{ matrix.target }}
+ # PR metadata for the preview strip the web app renders (a link back
+ # to the PR + its author). Passed via env, never interpolated into
+ # the script body.
+ PR_HTML_URL: ${{ github.event.pull_request.html_url }}
+ PR_AUTHOR: ${{ github.event.pull_request.user.login }}
run: |
set -euo pipefail
@@ -231,12 +237,28 @@ jobs:
fi
echo "${IMAGE} not found — building and pushing."
+
+ # Bake PR metadata into the web client bundle so previews render a
+ # top-of-page strip linking back to the PR (NEXT_PUBLIC_* is inlined
+ # at build time; the worker has no client bundle). The timestamp is
+ # the build time of this head commit, i.e. when the preview content
+ # last changed.
+ preview_meta_args=()
+ if [ "${TARGET}" = "web" ]; then
+ preview_meta_args+=(
+ --build-arg "NEXT_PUBLIC_PREVIEW_PR_URL=${PR_HTML_URL}"
+ --build-arg "NEXT_PUBLIC_PREVIEW_PR_AUTHOR=${PR_AUTHOR}"
+ --build-arg "NEXT_PUBLIC_PREVIEW_LAST_UPDATED=$(date -u +%Y-%m-%dT%H:%M:%SZ)"
+ )
+ fi
+
# EXTRA_BUILD_ARGS is a trusted workflow literal and must word-split
# into separate flags, so it is intentionally left unquoted.
# shellcheck disable=SC2086
docker build \
--build-arg NEXT_PUBLIC_BUILD_ID="${COMMIT_SHA}" \
${EXTRA_BUILD_ARGS} \
+ "${preview_meta_args[@]}" \
-f "${DOCKERFILE}" \
-t "${IMAGE}" \
.
diff --git a/web/Dockerfile b/web/Dockerfile
index 355e699eff..ea51374336 100644
--- a/web/Dockerfile
+++ b/web/Dockerfile
@@ -78,6 +78,12 @@ ARG NEXT_PUBLIC_DEMO_PROJECT_ID
ENV NEXT_PUBLIC_DEMO_PROJECT_ID=$NEXT_PUBLIC_DEMO_PROJECT_ID
ARG NEXT_PUBLIC_SIGN_UP_DISABLED
ENV NEXT_PUBLIC_SIGN_UP_DISABLED=$NEXT_PUBLIC_SIGN_UP_DISABLED
+ARG NEXT_PUBLIC_PREVIEW_PR_URL
+ENV NEXT_PUBLIC_PREVIEW_PR_URL=$NEXT_PUBLIC_PREVIEW_PR_URL
+ARG NEXT_PUBLIC_PREVIEW_PR_AUTHOR
+ENV NEXT_PUBLIC_PREVIEW_PR_AUTHOR=$NEXT_PUBLIC_PREVIEW_PR_AUTHOR
+ARG NEXT_PUBLIC_PREVIEW_LAST_UPDATED
+ENV NEXT_PUBLIC_PREVIEW_LAST_UPDATED=$NEXT_PUBLIC_PREVIEW_LAST_UPDATED
ARG NEXT_PUBLIC_POSTHOG_KEY
ENV NEXT_PUBLIC_POSTHOG_KEY=$NEXT_PUBLIC_POSTHOG_KEY
ARG NEXT_PUBLIC_POSTHOG_HOST
diff --git a/web/src/components/layouts/app-layout/variants/AuthenticatedLayout.tsx b/web/src/components/layouts/app-layout/variants/AuthenticatedLayout.tsx
index 784f7c5c7b..082b44eb27 100644
--- a/web/src/components/layouts/app-layout/variants/AuthenticatedLayout.tsx
+++ b/web/src/components/layouts/app-layout/variants/AuthenticatedLayout.tsx
@@ -69,6 +69,16 @@ const PaymentBanner = dynamic(
},
);
+const PreviewDeploymentBanner = dynamic(
+ () =>
+ import("@/src/features/preview-deployment-banner").then((mod) => ({
+ default: mod.PreviewDeploymentBanner,
+ })),
+ {
+ ssr: false,
+ },
+);
+
/** Grouped navigation structure returned by processNavigation */
type GroupedNavigation = {
ungrouped: NavigationItem[];
@@ -205,6 +215,7 @@ export function AuthenticatedLayout({
<SidebarProvider>
<div className="flex h-dvh w-full flex-col">
<PaymentBanner />
+ <PreviewDeploymentBanner />
<VersionUpdateBanner />
<div className="pt-banner-offset flex min-h-0 flex-1">
<ConnectedAppSidebar
diff --git a/web/src/env.mjs b/web/src/env.mjs
index 87dfd85471..13c33957c2 100644
--- a/web/src/env.mjs
+++ b/web/src/env.mjs
@@ -550,6 +550,11 @@ export const env = createEnv({
NEXT_PUBLIC_DEMO_PROJECT_ID: z.string().optional(),
NEXT_PUBLIC_DEMO_ORG_ID: z.string().optional(),
NEXT_PUBLIC_SIGN_UP_DISABLED: z.enum(["true", "false"]).default("false"),
+ // PR preview deployments only (.github/workflows/preview-build.yml):
+ // identify the environment with a top-of-page strip linking back to the PR.
+ NEXT_PUBLIC_PREVIEW_PR_URL: z.url().optional(),
+ NEXT_PUBLIC_PREVIEW_PR_AUTHOR: z.string().optional(),
+ NEXT_PUBLIC_PREVIEW_LAST_UPDATED: z.iso.datetime().optional(),
NEXT_PUBLIC_POSTHOG_KEY: z.string().optional(),
NEXT_PUBLIC_POSTHOG_HOST: z.string().optional(),
NEXT_PUBLIC_PLAIN_APP_ID: z.string().optional(),
@@ -585,6 +590,10 @@ export const env = createEnv({
NEXT_PUBLIC_LANGFUSE_BLOB_EXPORTER_CUTOFF:
process.env.NEXT_PUBLIC_LANGFUSE_BLOB_EXPORTER_CUTOFF,
NEXT_PUBLIC_SIGN_UP_DISABLED: process.env.NEXT_PUBLIC_SIGN_UP_DISABLED,
+ NEXT_PUBLIC_PREVIEW_PR_URL: process.env.NEXT_PUBLIC_PREVIEW_PR_URL,
+ NEXT_PUBLIC_PREVIEW_PR_AUTHOR: process.env.NEXT_PUBLIC_PREVIEW_PR_AUTHOR,
+ NEXT_PUBLIC_PREVIEW_LAST_UPDATED:
+ process.env.NEXT_PUBLIC_PREVIEW_LAST_UPDATED,
LANGFUSE_ENABLE_EXPERIMENTAL_FEATURES:
process.env.LANGFUSE_ENABLE_EXPERIMENTAL_FEATURES,
AWS_ACCESS_KEY_ID: process.env.AWS_ACCESS_KEY_ID,
diff --git a/web/src/features/preview-deployment-banner/PreviewDeploymentBanner.clienttest.tsx b/web/src/features/preview-deployment-banner/PreviewDeploymentBanner.clienttest.tsx
new file mode 100644
index 0000000000..898d6e0f00
--- /dev/null
+++ b/web/src/features/preview-deployment-banner/PreviewDeploymentBanner.clienttest.tsx
@@ -0,0 +1,69 @@
+import { render, screen } from "@testing-library/react";
+import { afterEach, describe, expect, it, vi } from "vitest";
+import { PreviewDeploymentBanner } from "./PreviewDeploymentBanner";
+
+// Shared mutable mock state (hoisted above the vi.mock factories).
+const h = vi.hoisted(() => ({
+ env: {} as Record<string, string | undefined>,
+}));
+
+vi.mock("@/src/env.mjs", () => ({ env: h.env }));
+// The container only reads the offset and registers its height; neither
+// affects the rendered content under test.
+vi.mock("@/src/features/top-banner", () => ({
+ useTopBanner: () => ({ getTopBannerOffset: () => 0 }),
+ useTopBannerRegistration: () => {},
+}));
+
+describe("PreviewDeploymentBanner", () => {
+ afterEach(() => {
+ for (const key of Object.keys(h.env)) delete h.env[key];
+ });
+
+ it("renders nothing when the preview env vars are unset", () => {
+ const { container } = render(<PreviewDeploymentBanner />);
+ expect(container).toBeEmptyDOMElement();
+ });
+
+ it("links the PR and the author and shows the update time", () => {
+ h.env.NEXT_PUBLIC_PREVIEW_PR_URL =
+ "https://github.com/langfuse/langfuse/pull/15580";
+ h.env.NEXT_PUBLIC_PREVIEW_PR_AUTHOR = "nmtrang29";
+ h.env.NEXT_PUBLIC_PREVIEW_LAST_UPDATED = new Date(
+ Date.now() - 2 * 60 * 60 * 1000,
+ ).toISOString();
+
+ render(<PreviewDeploymentBanner />);
+
+ expect(screen.getByRole("link", { name: "PR #15580" })).toHaveAttribute(
+ "href",
+ "https://github.com/langfuse/langfuse/pull/15580",
+ );
+ expect(screen.getByRole("link", { name: "@nmtrang29" })).toHaveAttribute(
+ "href",
+ "https://github.com/nmtrang29",
+ );
+ expect(screen.getByText(/updated about 2 hours ago/)).toBeInTheDocument();
+ });
+
+ it("omits the updated segment for an unparsable timestamp", () => {
+ h.env.NEXT_PUBLIC_PREVIEW_PR_URL =
+ "https://github.com/langfuse/langfuse/pull/1";
+ h.env.NEXT_PUBLIC_PREVIEW_LAST_UPDATED = "not-a-date";
+
+ render(<PreviewDeploymentBanner />);
+
+ expect(screen.getByRole("link", { name: "PR #1" })).toBeInTheDocument();
+ expect(screen.queryByText(/updated/)).not.toBeInTheDocument();
+ });
+
+ it("falls back to a generic link label when the URL has no PR number", () => {
+ h.env.NEXT_PUBLIC_PREVIEW_PR_URL = "https://github.com/langfuse/langfuse";
+
+ render(<PreviewDeploymentBanner />);
+
+ expect(
+ screen.getByRole("link", { name: "a pull request" }),
+ ).toBeInTheDocument();
+ });
+});
diff --git a/web/src/features/preview-deployment-banner/PreviewDeploymentBanner.tsx b/web/src/features/preview-deployment-banner/PreviewDeploymentBanner.tsx
new file mode 100644
index 0000000000..e4c80919d5
--- /dev/null
+++ b/web/src/features/preview-deployment-banner/PreviewDeploymentBanner.tsx
@@ -0,0 +1,56 @@
+import { useRef } from "react";
+import { formatDistanceToNow } from "date-fns";
+import {
+ useTopBanner,
+ useTopBannerRegistration,
+} from "@/src/features/top-banner";
+import { env } from "@/src/env.mjs";
+import { PreviewDeploymentBannerView } from "./PreviewDeploymentBannerView";
+
+const PREVIEW_BANNER_ID = "preview-deployment-banner";
+const PREVIEW_BANNER_ORDER = 20;
+
+/**
+ * Top-of-page strip shown on PR preview deployments only. The env vars are
+ * baked into preview web images by .github/workflows/preview-build.yml; they
+ * are unset everywhere else, so the banner never renders outside previews.
+ */
+export function PreviewDeploymentBanner() {
+ const bannerRef = useRef<HTMLDivElement>(null);
+ const { getTopBannerOffset } = useTopBanner();
+
+ const prUrl = env.NEXT_PUBLIC_PREVIEW_PR_URL;
+
+ useTopBannerRegistration({
+ bannerId: PREVIEW_BANNER_ID,
+ order: PREVIEW_BANNER_ORDER,
+ isVisible: Boolean(prUrl),
+ elementRef: bannerRef,
+ });
+
+ if (!prUrl) {
+ return null;
+ }
+
+ const parsed = env.NEXT_PUBLIC_PREVIEW_LAST_UPDATED
+ ? new Date(env.NEXT_PUBLIC_PREVIEW_LAST_UPDATED)
+ : undefined;
+ const lastUpdated =
+ parsed && !Number.isNaN(parsed.getTime()) ? parsed : undefined;
+
+ return (
+ <PreviewDeploymentBannerView
+ ref={bannerRef}
+ prUrl={prUrl}
+ prNumber={/\/pull\/(\d+)/.exec(prUrl)?.[1]}
+ author={env.NEXT_PUBLIC_PREVIEW_PR_AUTHOR}
+ updatedText={
+ lastUpdated
+ ? formatDistanceToNow(lastUpdated, { addSuffix: true })
+ : undefined
+ }
+ updatedTitle={lastUpdated?.toLocaleString()}
+ topOffset={getTopBannerOffset(PREVIEW_BANNER_ORDER)}
+ />
+ );
+}
diff --git a/web/src/features/preview-deployment-banner/PreviewDeploymentBannerView.stories.tsx b/web/src/features/preview-deployment-banner/PreviewDeploymentBannerView.stories.tsx
new file mode 100644
index 0000000000..08c40e7344
--- /dev/null
+++ b/web/src/features/preview-deployment-banner/PreviewDeploymentBannerView.stories.tsx
@@ -0,0 +1,30 @@
+import preview from "../../../.storybook/preview";
+import { PreviewDeploymentBannerView } from "./PreviewDeploymentBannerView";
+
+const meta = preview.meta({
+ component: PreviewDeploymentBannerView,
+});
+
+/**
+ * The strip as it renders on a PR preview deployment: PR link, author, and
+ * when the preview content was last updated. It pins to the top of the
+ * viewport, as in the app.
+ */
+export const Default = meta.story({
+ args: {
+ prUrl: "https://github.com/langfuse/langfuse/pull/15580",
+ prNumber: "15580",
+ author: "nmtrang29",
+ updatedText: "2 hours ago",
+ },
+});
+
+/**
+ * Author and timestamp are optional — the strip degrades to just the PR link,
+ * and without a parseable PR number the link label falls back to a generic one.
+ */
+export const MinimalMetadata = meta.story({
+ args: {
+ prUrl: "https://github.com/langfuse/langfuse/pull/15580",
+ },
+});
diff --git a/web/src/features/preview-deployment-banner/PreviewDeploymentBannerView.tsx b/web/src/features/preview-deployment-banner/PreviewDeploymentBannerView.tsx
new file mode 100644
index 0000000000..1c681d2396
--- /dev/null
+++ b/web/src/features/preview-deployment-banner/PreviewDeploymentBannerView.tsx
@@ -0,0 +1,68 @@
+import { type Ref } from "react";
+
+export type PreviewDeploymentBannerViewProps = {
+ /** Link back to the pull request this preview deployment belongs to. */
+ prUrl: string;
+ /** PR number for the link label; falls back to a generic label when absent. */
+ prNumber?: string;
+ /** GitHub login of the PR author. */
+ author?: string;
+ /** Human-readable relative time the preview was last updated, e.g. "2 hours ago". */
+ updatedText?: string;
+ /** Absolute timestamp shown on hover — the relative text is computed at render
+ * time and goes stale in a long-lived tab. */
+ updatedTitle?: string;
+ /** Vertical offset when stacked below other top banners. */
+ topOffset?: number;
+ ref?: Ref<HTMLDivElement>;
+};
+
+export function PreviewDeploymentBannerView({
+ prUrl,
+ prNumber,
+ author,
+ updatedText,
+ updatedTitle,
+ topOffset = 0,
+ ref,
+}: PreviewDeploymentBannerViewProps) {
+ return (
+ <div
+ ref={ref}
+ className="border-preview-banner-border bg-preview-banner text-preview-banner-foreground fixed z-51 flex w-full items-center justify-center border-b px-4 py-1"
+ style={{ top: topOffset }}
+ >
+ <span className="text-sm">
+ Preview deployment of{" "}
+ <a
+ href={prUrl}
+ target="_blank"
+ rel="noopener noreferrer"
+ className="text-preview-banner-link hover:text-preview-banner-link-hover font-bold hover:underline"
+ >
+ {prNumber ? `PR #${prNumber}` : "a pull request"}
+ </a>
+ {author ? (
+ <>
+ {" "}
+ by{" "}
+ <a
+ href={`https://github.com/${encodeURIComponent(author)}`}
+ target="_blank"
+ rel="noopener noreferrer"
+ className="text-preview-banner-link hover:text-preview-banner-link-hover font-bold hover:underline"
+ >
+ @{author}
+ </a>
+ </>
+ ) : null}
+ {updatedText ? (
+ <>
+ {" "}
+ · <span title={updatedTitle}>updated {updatedText}</span>
+ </>
+ ) : null}
+ </span>
+ </div>
+ );
+}
diff --git a/web/src/features/preview-deployment-banner/index.ts b/web/src/features/preview-deployment-banner/index.ts
new file mode 100644
index 0000000000..0a5341b127
--- /dev/null
+++ b/web/src/features/preview-deployment-banner/index.ts
@@ -0,0 +1 @@
+export { PreviewDeploymentBanner } from "./PreviewDeploymentBanner";
diff --git a/web/src/styles/globals.css b/web/src/styles/globals.css
index 5aed1bf5ae..567e26a960 100644
--- a/web/src/styles/globals.css
+++ b/web/src/styles/globals.css
@@ -60,6 +60,11 @@
--color-primary-accent: hsl(var(--primary-accent));
--color-link: hsl(var(--link));
--color-link-hover: hsl(var(--link-hover));
+ --color-preview-banner: hsl(var(--preview-banner));
+ --color-preview-banner-foreground: hsl(var(--preview-banner-foreground));
+ --color-preview-banner-border: hsl(var(--preview-banner-border));
+ --color-preview-banner-link: hsl(var(--preview-banner-link));
+ --color-preview-banner-link-hover: hsl(var(--preview-banner-link-hover));
--color-control-fill: hsl(var(--control-fill));
--color-control-track: hsl(var(--control-track));
--color-control-border: hsl(var(--control-border));
@@ -292,6 +297,14 @@
loudest thing on a light page — with a clearly darker hover step. */
--link: 246 40% 50%;
--link-hover: 246 55% 36%;
+ /* Preview-deployment strip (PR previews only): soft blue tint with text
+ darker than the fill, links a step brighter than body text. Values are
+ the blue-100/950/200/700/800 ramp. */
+ --preview-banner: 214 95% 93%;
+ --preview-banner-foreground: 226 57% 21%;
+ --preview-banner-border: 213 97% 87%;
+ --preview-banner-link: 224 76% 48%;
+ --preview-banner-link-hover: 226 71% 40%;
/* Checked selection controls (checkbox/switch): monochrome in BOTH
modes — dark fill + light glyph in light, muted-white fill + dark
glyph in dark. Deliberately dimmer than --primary in dark so checked
@@ -454,6 +467,15 @@
--primary-accent: 246 55% 70%;
--link: 246 55% 70%;
--link-hover: 246 95% 85%;
+ /* Preview-deployment strip: fill is blue-500/25 precomposed over the 6%
+ canvas, border is blue-300/20 precomposed over that fill — the strip
+ needs opaque colors. Body text stays on the neutral foreground tier;
+ links are blue-400/300. */
+ --preview-banner: 217 47% 19%;
+ --preview-banner-foreground: 0 0% 70%;
+ --preview-banner-border: 215 37% 31%;
+ --preview-banner-link: 213 94% 68%;
+ --preview-banner-link-hover: 212 96% 78%;
--control-fill: 0 0% 78%;
--control-track: 0 0% 24%;
/* Matches --border-contrast: unchecked checkboxes/radios read by their