From 5bfbc543e1a3f51e1c8cc7166bddaaf32e711bc2 Mon Sep 17 00:00:00 2001 From: im-rk Date: Sat, 3 Oct 2026 15:46:44 +0530 Subject: [PATCH] fix(search): ResultCard is a client component, so Find and Ask results render again --- CHANGELOG.md | 1 + docs/TESTING.md | 3 +++ src/components/ResultCard.tsx | 2 ++ tests/unit/client-boundary.test.ts | 37 ++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+) create mode 100644 tests/unit/client-boundary.test.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index caf5bf4..93a9d62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ Format: [Keep a Changelog](https://keepachangelog.com/); versioning: [SemVer](ht - Cloudinary asset index: tags and contextual metadata on each session's asset, synced from the Studio and read back with the Search API (Phase 19) ### Fixed +- `/search` (Find and Ask results) crashed with "Something went wrong" since the data saver release: `ResultCard` called a client hook without `"use client"`. Fixed, with a unit test that fails the build for any hook used outside a client file - Phone header: Studio, data saver and the theme switch were off-screen below ~560 px. Header, Studio and /try now fit 360 px (Phase 23) ## [1.0.0] — 2026-10-03 diff --git a/docs/TESTING.md b/docs/TESTING.md index 1130c97..cb5f92e 100644 --- a/docs/TESTING.md +++ b/docs/TESTING.md @@ -28,6 +28,9 @@ Against the **deployed** `APP_URL`: home → search a known phrase → result op - `revision.spec.ts`: a wrong quiz answer appears under Weak spots with a revision reel and clears; study notes carry timestamp links and download as Markdown - `mobile.spec.ts`: at 360 px the header's Studio, data saver and theme controls are on screen and no page scrolls sideways +### Client boundary guard +`tests/unit/client-boundary.test.ts` fails if any file under `src` calls a React or Pravaha hook without `"use client"`. A hook in a Server Component crashes the page at request time and neither `tsc` nor ESLint notices (it broke `/search` in production once). After every deploy, also run the smoke spec: `APP_URL= npx playwright test tests/e2e/smoke.spec.ts`. + ## AI Eval (`pnpm eval:ask`) 10 questions (7 answerable, 3 not) against the demo library; results recorded in `AI_EVALUATION.md`. diff --git a/src/components/ResultCard.tsx b/src/components/ResultCard.tsx index 269798e..57b0a0c 100644 --- a/src/components/ResultCard.tsx +++ b/src/components/ResultCard.tsx @@ -1,3 +1,5 @@ +"use client"; + import Image from "next/image"; import Link from "next/link"; diff --git a/tests/unit/client-boundary.test.ts b/tests/unit/client-boundary.test.ts new file mode 100644 index 0000000..6317a9b --- /dev/null +++ b/tests/unit/client-boundary.test.ts @@ -0,0 +1,37 @@ +import { readdirSync, readFileSync } from "node:fs"; +import { join } from "node:path"; +import { describe, expect, it } from "vitest"; + +// A React hook called from a Server Component crashes the page at request time, and neither the type checker +// nor the linter notices (the /search page broke in production this way when a hook was added to a component +// that had no "use client"). This guard fails the build instead: every file that calls a hook must be a client file. +const HOOK_CALL = /\buse(State|Effect|LayoutEffect|Ref|Memo|Callback|Reducer|SyncExternalStore|Router|Pathname|SearchParams|LiteUrl|DataSaver|SavedMoments|RecentQuestions|WatchProgress|WeakSpots)\s*\(/; + +function files(dir: string): string[] { + return readdirSync(dir, { withFileTypes: true }).flatMap((e) => { + const path = join(dir, e.name); + return e.isDirectory() ? files(path) : /\.(ts|tsx)$/.test(e.name) ? [path] : []; + }); +} + +const code = (source: string) => + source + .split("\n") + .filter((line) => !/^\s*(\/\/|\*|\/\*)/.test(line)) + .join("\n"); + +describe("client boundary", () => { + const all = files(join(process.cwd(), "src")); + + it("finds the source files", () => { + expect(all.length).toBeGreaterThan(50); + }); + + it("marks every file that calls a hook with \"use client\"", () => { + const offenders = all.filter((path) => { + const source = readFileSync(path, "utf8"); + return HOOK_CALL.test(code(source)) && !/^\s*(["'])use client\1/.test(source); + }); + expect(offenders.map((p) => p.replace(process.cwd(), ""))).toEqual([]); + }); +});