Skip to content
Merged
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
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The repository holds one Next.js app that serves two sites:

How the two sites share the app:

- **Hosts.** bench's routes are under `/bench`. `next.config.mjs` rewrites every path on bench.vortex.dev onto `/bench`, before the filesystem, so bench's public URLs are the root paths they always were (`/`, `/chart/{slug}`, `/api/…`). Previews, local dev and a deployment's own URL serve bench at `/bench`. vortex.dev and www.vortex.dev do not: `/bench` 404s there, except `/bench/api/health`, which the Vercel cron may call on any of the deployment's hosts. bench builds every root-relative link and fetch with `benchPath()` (`src/bench/lib/base-path.ts`): bench's root layout reads the request's host and hands the base to client components (`src/bench/components/BenchBase.tsx`).
- **Hosts.** bench's routes are under `/bench`. `next.config.mjs` rewrites every path on bench.vortex.dev onto `/bench`, before the filesystem, so bench's public URLs are the root paths they always were (`/`, `/chart/{slug}`, `/api/…`). Previews, local dev and a deployment's own URL serve bench at `/bench`. vortex.dev and www.vortex.dev do not: `/bench` 404s there, except `/bench/api/health`, which the Vercel cron may call on any of the deployment's hosts. bench builds every root-relative link and fetch with `benchPath()` (`src/bench/lib/base-path.ts`): bench's root layout reads the request's host and hands the base to client components (`src/bench/components/BenchBase.tsx`). The site's links to bench go through `benchHref()` (`src/lib/bench-link.ts`): https://bench.vortex.dev on production (`VERCEL_ENV`, which `next.config.mjs` embeds at build time), and the deployment's own `/bench` everywhere else, so a preview's links stay on the preview.
- **Root layouts.** Each site has its own, so Next.js has none to draw an unmatched URL's 404 in. `src/app/global-not-found.tsx` (`experimental.globalNotFound`) is the site's 404, in the site's layout, prerendered for every unmatched URL; a catch-all route (`src/app/(bench)/bench/[...notFound]`) keeps bench's unmatched paths out of it. bench has no `not-found.tsx`, so those paths get Next.js's default 404 document, with bench's metadata but without bench's layout. `robots.ts` stays at the app root, where Next.js reads it; the favicon is `public/favicon.ico`, named in the site's metadata, because the `app/favicon.ico` convention would also put it on bench's pages. Next.js serves a metadata image route inside a route group with a hash suffix (`/opengraph-image-12o0cb`), and the og:image tags name that URL; rewrites in `next.config.mjs` keep the plain `/opengraph-image` URLs (which the posts' JSON-LD names) serving the same images.
- **Headers.** The CSP and the other security headers in `next.config.mjs` cover both sites: one policy, since both self-host their fonts. bench now sends the site's security headers, including `X-Frame-Options: DENY` and `frame-ancestors 'none'`, so no other site can embed bench's pages in a frame. `vercel.json` holds bench's cron (`/bench/api/health`) and bench's CDN rule for its landing, chart, and methodology pages on bench.vortex.dev (header rules match the path as requested, before the rewrites). bench's HTML differs between its two URL forms, so the `/bench` form gets the CDN rule only outside production (`benchPrefixCdnRules` in `next.config.mjs`): a cached `/bench` page must never answer for bench.vortex.dev.
- **Toolchain.** One package: one `package.json`, one `bun.lock`, one `bunfig.toml`, one `tsconfig.json`. Next.js 16.4.1, React 19.3 and TypeScript 7. `tsconfig.json` has every strict flag either app had, including bench's `noFallthroughCasesInSwitch` and `noUncheckedSideEffectImports`; `src/css.d.ts` types the CSS side-effect imports. The root `biome.json` lints and formats both sites: an override keeps bench's files (`src/bench`, `src/app/(bench)`, the parity and deploy checks, `vitest.config.ts`) in bench's old Prettier style (single quotes, trailing commas, 100 columns) with bench's lint rules (see "bench" below), and `bun run check:ci` checks all of it. bench's tests run on Vitest from the root `vitest.config.ts`, scoped to bench's files; the site's run on `bun test`. bench's PostCSS config sits beside its stylesheets (`src/bench/styles/postcss.config.mjs`), and Turbopack applies it to those alone: with no config at the root, the site's CSS gets Turbopack's defaults.
Expand Down
6 changes: 5 additions & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ const nextConfig = wrapWithPlausible({
// deployed build however the runtime is configured. Vercel sets the
// variable during its builds.
env: {
VERCEL_GIT_COMMIT_SHA: process.env.VERCEL_GIT_COMMIT_SHA ?? "unknown"
VERCEL_GIT_COMMIT_SHA: process.env.VERCEL_GIT_COMMIT_SHA ?? "unknown",
// Which deployment this is, for the site's links to bench
// (src/lib/bench-link.ts): bench.vortex.dev on production, this
// deployment's /bench elsewhere. Embedded so client components see it.
VERCEL_ENV: process.env.VERCEL_ENV ?? ""
},
async headers() {
return [
Expand Down
5 changes: 2 additions & 3 deletions src/components/results-table/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { OpenInNewIcon } from "@/components/icons";
import { benchHref } from "@/lib/bench-link";
import { formatReadDate, type Panel } from "@/lib/bench-summary";
import { resultsRow, resultsSystems } from "@/vendor/vortex-design/results.js";

const SOURCE_URL = "https://bench.vortex.dev";

const classes = (...names: (string | false)[]) =>
names.filter(Boolean).join(" ") || undefined;

Expand Down Expand Up @@ -31,7 +30,7 @@ export function ResultsTable({
<p className="vx-results-head">
<span>File format benchmarks</span>
<span className="vx-label-sm vx-results-src">
<a className="vx-source vx-nav-link" href={SOURCE_URL}>
<a className="vx-source vx-nav-link" href={benchHref()}>
bench.vortex.dev
<OpenInNewIcon />
</a>
Expand Down
24 changes: 24 additions & 0 deletions src/lib/bench-link.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/** bench's public address, which production's links name. */
const BENCH_ORIGIN = "https://bench.vortex.dev";

/**
* A link from the site to a bench page (`""` or `/` for the landing page,
* `/methodology`, `/chart/{slug}`, …). Production links to bench.vortex.dev,
* where bench is served from the root. Every other deployment (a preview, a
* local build) serves bench under `/bench` on its own host, so its links stay
* on that deployment rather than leaving for production. `next.config.mjs`
* embeds `VERCEL_ENV` at build time, so a client component agrees with the
* server render.
*/
export function benchHref(
path = "",
vercelEnv: string | undefined = process.env.VERCEL_ENV
): string {
if (path !== "" && !path.startsWith("/")) {
throw new Error(`benchHref takes a root-relative path, not ${path}`);
}
if (vercelEnv === "production") {
return `${BENCH_ORIGIN}${path}`;
}
return path === "" || path === "/" ? "/bench" : `/bench${path}`;
}
8 changes: 4 additions & 4 deletions src/lib/faq.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { benchHref } from "@/lib/bench-link";
import { formatReadDate, type Panel } from "@/lib/bench-summary";
import { baseUrl } from "@/lib/constants";
import { GPU_DETAIL, GPU_PANEL } from "@/lib/gpu-result";
Expand All @@ -12,7 +13,6 @@ import {

const REPO = "https://github.com/vortex-data/vortex";
const DOCS = "https://docs.vortex.dev";
const BENCH = "https://bench.vortex.dev";

// What each speed panel measures, in a few words, by panel title
// (bench-summary.ts and gpu-result.ts), for the answer that says where
Expand Down Expand Up @@ -163,8 +163,8 @@ export function faqs({
}),
...(hasGpu && { after: [GPU_DETAIL] }),
links: [
{ href: `${BENCH}/`, label: "Every benchmark on bench.vortex.dev" },
{ href: `${BENCH}/methodology`, label: "How the benchmarks run" }
{ href: benchHref("/"), label: "Every benchmark on bench.vortex.dev" },
{ href: benchHref("/methodology"), label: "How the benchmarks run" }
]
},
{
Expand Down Expand Up @@ -219,7 +219,7 @@ export function faqs({
"Both formats are under the Apache License 2.0. Vortex is a Linux Foundation project. LF Projects, part of the Linux Foundation, holds the Vortex trademark, and the charter keeps the project's code under the Apache License. Changing the charter takes a two-thirds vote of the Technical Steering Committee and the approval of LF Projects. Lance has its own governance, but the name and code are held by a private company (LanceDB) instead of an independent foundation."
],
links: [
{ href: `${BENCH}/`, label: "Every benchmark on bench.vortex.dev" },
{ href: benchHref("/"), label: "Every benchmark on bench.vortex.dev" },
{
href: `${baseUrl}/charter.pdf`,
label: "The Vortex Technical Charter"
Expand Down
4 changes: 3 additions & 1 deletion src/lib/nav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export type NavLink = {
current: "page" | "true" | null;
};

import { benchHref } from "@/lib/bench-link";

const SITE = "https://vortex.dev";

/**
Expand All @@ -40,7 +42,7 @@ export function navLinks(
},
{
label: "Benchmarks",
href: bench ? bench.home : "https://bench.vortex.dev",
href: bench ? bench.home : benchHref(),
internal: false,
current: bench ? (benchLanding ? "page" : "true") : null
},
Expand Down
10 changes: 8 additions & 2 deletions tests/smoke.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { expect, type Page, test } from "@playwright/test";
import { externalPosts } from "../src/content/links";

// The site's links to bench (src/lib/bench-link.ts): bench.vortex.dev on
// production, the deployment's own /bench on a preview or a local build.
const BENCH_HREF = /^(https:\/\/bench\.vortex\.dev|\/bench)$/;

/**
* Browser smoke tests. Structural and behavioral checks against a real
* browser engine — catches regressions the HTTP-only verify script can't
Expand Down Expand Up @@ -197,8 +201,10 @@ test.describe("home bands", () => {
await expect(table.locator("tbody tr")).toHaveCount(7);
await expect(table.locator("tbody td.is-ours")).toHaveCount(7);
await expect(table).toContainText(/read \d+ \w{3} \d{4}/);
const source = table.locator('a[href="https://bench.vortex.dev"]');
// bench.vortex.dev on production, this deployment's /bench elsewhere.
const source = table.locator("a.vx-source");
await expect(source).toBeVisible();
await expect(source).toHaveAttribute("href", BENCH_HREF);
await expect(source).toHaveText("bench.vortex.dev");
});

Expand Down Expand Up @@ -533,7 +539,7 @@ test.describe("header", () => {
const nav = page.getByRole("navigation", { name: "Primary" });
for (const [name, href] of [
["Docs", "https://docs.vortex.dev"],
["Benchmarks", "https://bench.vortex.dev"],
["Benchmarks", BENCH_HREF],
["Explorer", "https://explore.vortex.dev"],
["Blog", "/blog"]
] as const) {
Expand Down
26 changes: 26 additions & 0 deletions tests/unit/bench-link.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import assert from "node:assert/strict";
import { describe, it } from "node:test";
import { benchHref } from "@/lib/bench-link";

describe("benchHref", () => {
it("names bench.vortex.dev on production", () => {
assert.equal(benchHref("", "production"), "https://bench.vortex.dev");
assert.equal(benchHref("/", "production"), "https://bench.vortex.dev/");
assert.equal(
benchHref("/methodology", "production"),
"https://bench.vortex.dev/methodology"
);
});

it("stays on the deployment's /bench everywhere else", () => {
for (const env of ["preview", "development", "", undefined]) {
assert.equal(benchHref("", env), "/bench");
assert.equal(benchHref("/", env), "/bench");
assert.equal(benchHref("/methodology", env), "/bench/methodology");
}
});

it("refuses a path that is not root-relative", () => {
assert.throws(() => benchHref("methodology", "production"));
});
});
3 changes: 2 additions & 1 deletion tests/unit/nav.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ describe("navLinks", () => {
"Explorer",
"Blog"
]);
assert.equal(links.Benchmarks?.href, "https://bench.vortex.dev");
// Outside production, the deployment's own /bench (bench-link.ts).
assert.equal(links.Benchmarks?.href, "/bench");
assert.equal(links.Blog?.href, "/blog");
assert.equal(links.Blog?.internal, true);
assert.equal(links.Blog?.current, "page");
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/results-table.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { describe, it } from "node:test";
import { renderToStaticMarkup } from "react-dom/server";
import { OpenInNewIcon } from "@/components/icons";
import { ResultsTable } from "@/components/results-table";
import { benchHref } from "@/lib/bench-link";
import { formatReadDate, panelsFrom } from "@/lib/bench-summary";
import { renderResults } from "@/vendor/vortex-design/results.js";

Expand All @@ -26,10 +27,12 @@ describe("ResultsTable", () => {
const html = renderToStaticMarkup(
<ResultsTable panels={PANELS} readAt={READ} />
);
// The system names bench.vortex.dev; the site names it on production
// and its own /bench elsewhere (bench-link.ts), the one difference.
const system = renderResults(PANELS, {
read: formatReadDate(READ),
icon: renderToStaticMarkup(<OpenInNewIcon />)
});
}).replace('href="https://bench.vortex.dev"', `href="${benchHref()}"`);
assert.equal(html, system);
});

Expand Down
Loading