🪢 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
refactor(web): Fix no-null-render: PreviewDeploymentBanner.tsx (#17225)
Ben Bachem8f5ed07b1d2b
diff --git a/web/src/components/layouts/app-layout/variants/AuthenticatedLayout.tsx b/web/src/components/layouts/app-layout/variants/AuthenticatedLayout.tsxindex 87eba7f125..38e770ee6d 100644--- a/web/src/components/layouts/app-layout/variants/AuthenticatedLayout.tsx+++ b/web/src/components/layouts/app-layout/variants/AuthenticatedLayout.tsx@@ -262,7 +262,11 @@ export function AuthenticatedLayout({<SidebarProvider><div className="flex h-dvh w-full flex-col"><PaymentBanner />- <PreviewDeploymentBanner />+ {env.NEXT_PUBLIC_PREVIEW_PR_URL && (+ <PreviewDeploymentBanner+ prUrl={env.NEXT_PUBLIC_PREVIEW_PR_URL}+ />+ )}{versionUpdatePrompt.isVisible && (<VersionUpdateBanneronReload={versionUpdatePrompt.reload}diff --git a/web/src/features/preview-deployment-banner/PreviewDeploymentBanner.clienttest.tsx b/web/src/features/preview-deployment-banner/PreviewDeploymentBanner.clienttest.tsxindex 898d6e0f00..9c836681bb 100644--- a/web/src/features/preview-deployment-banner/PreviewDeploymentBanner.clienttest.tsx+++ b/web/src/features/preview-deployment-banner/PreviewDeploymentBanner.clienttest.tsx@@ -20,11 +20,6 @@ describe("PreviewDeploymentBanner", () => {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";@@ -33,7 +28,11 @@ describe("PreviewDeploymentBanner", () => {Date.now() - 2 * 60 * 60 * 1000,).toISOString();- render(<PreviewDeploymentBanner />);+ render(+ <PreviewDeploymentBanner+ prUrl={h.env.NEXT_PUBLIC_PREVIEW_PR_URL as string}+ />,+ );expect(screen.getByRole("link", { name: "PR #15580" })).toHaveAttribute("href",@@ -51,7 +50,11 @@ describe("PreviewDeploymentBanner", () => {"https://github.com/langfuse/langfuse/pull/1";h.env.NEXT_PUBLIC_PREVIEW_LAST_UPDATED = "not-a-date";- render(<PreviewDeploymentBanner />);+ render(+ <PreviewDeploymentBanner+ prUrl={h.env.NEXT_PUBLIC_PREVIEW_PR_URL as string}+ />,+ );expect(screen.getByRole("link", { name: "PR #1" })).toBeInTheDocument();expect(screen.queryByText(/updated/)).not.toBeInTheDocument();@@ -60,7 +63,11 @@ describe("PreviewDeploymentBanner", () => {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 />);+ render(+ <PreviewDeploymentBanner+ prUrl={h.env.NEXT_PUBLIC_PREVIEW_PR_URL as string}+ />,+ );expect(screen.getByRole("link", { name: "a pull request" }),diff --git a/web/src/features/preview-deployment-banner/PreviewDeploymentBanner.tsx b/web/src/features/preview-deployment-banner/PreviewDeploymentBanner.tsxindex bc91605211..ec26ba475f 100644--- a/web/src/features/preview-deployment-banner/PreviewDeploymentBanner.tsx+++ b/web/src/features/preview-deployment-banner/PreviewDeploymentBanner.tsx@@ -1,4 +1,3 @@-/* eslint-disable @repo/no-null-render */import { useRef } from "react";import { formatDistanceToNow } from "date-fns";import {@@ -16,23 +15,17 @@ const PREVIEW_BANNER_ORDER = 20;* 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() {+export function PreviewDeploymentBanner({ prUrl }: { prUrl: string }) {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),+ isVisible: true,elementRef: bannerRef,});- if (!prUrl) {- return null;- }-const parsed = env.NEXT_PUBLIC_PREVIEW_LAST_UPDATED? new Date(env.NEXT_PUBLIC_PREVIEW_LAST_UPDATED): undefined;