Skip to content

Commit 9034f2a

Browse files
Add Pagefind searchbar to apps/web header (#2075)
* Add Pagefind searchbar to apps/web header - Install vite-plugin-pagefind and pagefind dependencies - Configure pagefind plugin in vite.config.ts - Update build script to run pagefind after vite build - Create Search component using Pagefind UI - Add Search component to header - Import Pagefind UI CSS in styles.css Co-Authored-By: yujonglee <[email protected]> * Fix pagefind CSS import and add cleanup function - Move CSS import from styles.css to dynamic loading in Search component - Add cleanup function to destroy PagefindUI instance on unmount - Fixes build error: ENOENT /pagefind/pagefind-ui.css during vite build Co-Authored-By: yujonglee <[email protected]> * wip --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent d30d15d commit 9034f2a

File tree

5 files changed

+114
-3
lines changed

5 files changed

+114
-3
lines changed

apps/web/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
"type": "module",
55
"scripts": {
66
"dev": "VITE_APP_URL=\"http://localhost:3000\" dotenvx run --ignore MISSING_ENV_FILE -f ../../.env.supabase -f ../../.env.restate -f .env -- vite dev --port 3000",
7-
"build": "vite build",
7+
"build": "vite build && pagefind --site ./dist/client",
88
"serve": "vite preview",
99
"test": "playwright test",
10-
"typecheck": "pnpm -F @hypr/web build && tsc --project tsconfig.json --noEmit",
10+
"typecheck": "CI=true pnpm -F @hypr/web build && tsc --project tsconfig.json --noEmit",
1111
"gen:agents": "node scripts/gen-agents.js"
1212
},
1313
"dependencies": {
@@ -77,6 +77,7 @@
7777
"@vitejs/plugin-react": "^5.1.1",
7878
"jsdom": "^27.2.0",
7979
"netlify": "^23.11.1",
80+
"pagefind": "^1.4.0",
8081
"tanstack-router-sitemap": "^1.0.13",
8182
"typescript": "^5.9.3",
8283
"vite": "^7.2.4",

apps/web/src/components/header.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from "lucide-react";
99
import { useState } from "react";
1010

11+
import { Search } from "@/components/search";
1112
import { useDocsDrawer } from "@/hooks/use-docs-drawer";
1213
import { getPlatformCTA, usePlatform } from "@/hooks/use-platform";
1314

@@ -176,6 +177,7 @@ export function Header() {
176177
</div>
177178

178179
<nav className="hidden sm:flex items-center gap-2">
180+
<Search />
179181
<Link
180182
to="/join-waitlist"
181183
className="px-4 h-8 flex items-center text-sm text-neutral-600 hover:text-neutral-800 transition-all hover:underline decoration-dotted"

apps/web/src/components/search.tsx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { useEffect, useRef } from "react";
2+
3+
export function Search() {
4+
const containerRef = useRef<HTMLDivElement>(null);
5+
6+
useEffect(() => {
7+
let pagefindInstance: { destroy?: () => void } | null = null;
8+
9+
const loadPagefind = async () => {
10+
if (!containerRef.current) return;
11+
12+
const linkId = "pagefind-ui-css";
13+
if (!document.getElementById(linkId)) {
14+
const link = document.createElement("link");
15+
link.id = linkId;
16+
link.rel = "stylesheet";
17+
link.href = "/pagefind/pagefind-ui.css";
18+
document.head.appendChild(link);
19+
}
20+
21+
try {
22+
const pagefindPath = "/pagefind/pagefind-ui.js";
23+
const pagefindUI = await import(/* @vite-ignore */ pagefindPath);
24+
pagefindInstance = new pagefindUI.PagefindUI({
25+
element: containerRef.current,
26+
showSubResults: true,
27+
showImages: false,
28+
});
29+
} catch {}
30+
};
31+
32+
loadPagefind();
33+
34+
return () => {
35+
if (pagefindInstance?.destroy) {
36+
pagefindInstance.destroy();
37+
}
38+
};
39+
}, []);
40+
41+
return <div ref={containerRef} />;
42+
}

apps/web/src/env.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createEnv } from "@t3-oss/env-core";
22
import { z } from "zod";
33

4+
const isCI = process.env.CI === "true";
45
const isDev = process.env.NODE_ENV === "development";
56

67
export const env = createEnv({
@@ -34,5 +35,5 @@ export const env = createEnv({
3435

3536
runtimeEnv: { ...process.env, ...import.meta.env },
3637
emptyStringAsUndefined: true,
37-
skipValidation: process.env.CI === "true",
38+
skipValidation: isCI,
3839
});

pnpm-lock.yaml

Lines changed: 65 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)