From ab6cd7c1622a66127b608f780807168823161c81 Mon Sep 17 00:00:00 2001 From: spaghet Date: Wed, 4 Nov 2026 22:16:17 -0500 Subject: [PATCH] Refactor components and add tests for improved functionality and coverage --- astro.config.mjs | 13 ++- src/components/Blog.tsx | 33 ++++---- src/components/Drawer.astro | 7 +- src/components/Header.astro | 11 ++- src/components/Projects.tsx | 30 +++---- src/components/__tests__/list-islands.test.ts | 83 +++++++++++++++++++ src/lib/__tests__/content.test.ts | 34 +++++++- src/lib/__tests__/utils.test.ts | 30 ++++++- src/lib/content.ts | 20 +++++ src/lib/types.ts | 5 +- src/lib/utils.ts | 25 ++++++ src/styles/global.css | 13 ++- vitest.config.ts | 3 + 13 files changed, 253 insertions(+), 54 deletions(-) create mode 100644 src/components/__tests__/list-islands.test.ts diff --git a/astro.config.mjs b/astro.config.mjs index 4350070..c5416ec 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -12,6 +12,17 @@ export default defineConfig({ output: "server", adapter: node({ mode: "ssr" }), vite: { - plugins: [tailwindcss()] + plugins: [tailwindcss()], + optimizeDeps: { + // Client-island deps that are not reachable from the SSR entry graph are + // discovered mid-session, which makes Vite re-optimize and bump the browserHash. + // Every already-served island module then 504s with "Outdated Optimize Dep", + // hydration aborts, and the Solid lists on /blog, /projects and /search stay + // empty. Pre-declaring them bundles them at startup so the hash never changes + // underneath a page. Keep this list in sync with the imports of every + // src/components/*.tsx island (solid-js, @lib/utils -> clsx + tailwind-merge, + // @lib/search -> fuse.js). + include: ["solid-js", "solid-js/web", "clsx", "tailwind-merge", "fuse.js"], + }, } }) diff --git a/src/components/Blog.tsx b/src/components/Blog.tsx index 44ccbde..7a56390 100644 --- a/src/components/Blog.tsx +++ b/src/components/Blog.tsx @@ -1,7 +1,8 @@ import type { BlogPost } from "@lib/types" -import { createEffect, createSignal, For } from "solid-js" +import { createMemo, createSignal, For } from "solid-js" import ArrowCard from "@components/ArrowCard" import { cn } from "@lib/utils" +import { filterByTags } from "@lib/content" type Props = { tags: string[] @@ -10,20 +11,12 @@ type Props = { export default function Blog({ data, tags }: Props) { const [filter, setFilter] = createSignal(new Set()) - const [posts, setPosts] = createSignal([]) - createEffect(() => { - setPosts(data.filter((entry) => { - // Filter by tags - const tagMatch = Array.from(filter()).every((value) => - entry.tags.some((tag:string) => - tag.toLowerCase() === String(value).toLowerCase() - ) - ) - - return tagMatch - })) - }) + // `createMemo`, not `createEffect` + a signal: effects never run during SSR, so the + // signal stayed at its initial `[]` and the server emitted "SHOWING 0 OF 3" with an + // empty