# A full health check on my personal site: duplicated code, outdated idioms, and a test that failed 3 out of 5 times

> Five months, 900 files, many features built by parallel AI sessions. Three small Node scripts found duplicated code and old idioms: 115 files, net minus 596 lines, plus a 24:05 midnight bug and a flaky E2E.

- Date: 2026-11-30
- Topics: Next.js, Debugging, Accessibility
- Chinese original: https://kbs0830.com/blog/codebase-health-check-node26-tailwind4

This site has been in development since June 2026, and git tracks around 900 files. In the last month, many features were built by running several Claude sessions in parallel: one on the live radar, one on small tools, one on the admin. Each session follows the rules, but none can see what the others just wrote, so the result is **the same thing written several times**.

This time I asked it to sweep the whole codebase, with these conditions: change only what is really a problem, the pages must not change visually, and every item has to pass the tests.

## No tools: three small scripts

The usual tools would be knip (unused files and exports) and jscpd (duplicate code). But this desktop is also the production server, and installing packages by hand is not allowed here (the deploy script installs them), so I wrote three Node scripts of a few dozen lines each and threw them away afterwards:

1. **Import graph**: resolve every file's `import` / `require` / `import()`, then list files that nothing references and that are not a Next.js entry point (`page.tsx`, `route.ts` …) or a test, and exported names that no other file uses
2. **Cross-file duplicate blocks**: strip blank lines, comments and imports from each file, hash every run of 7 consecutive normalized lines, and list any hash that shows up in two or more files
3. **Old-idiom rules**: 40-odd regexes, for example built-in modules without `node:`, `new Promise((r) => setTimeout(r, …))`, `JSON.parse(JSON.stringify(…))`, `forwardRef`, `<Context.Provider>`, Tailwind's `[--var]` bracket syntax

Deprecated React 19 and Next.js 16 idioms came out at **0**; earlier cleanups had already removed them. The remaining problems were concentrated in "the same thing written several times".

## Duplicated code

| What | Before | After |
|---|---|---|
| Share images (OG) | articles and projects each had a copy of a 100-line layout, with the font name and site name hard-coded | one shared `og-card.tsx`; the project image is pixel-for-pixel identical between old and new |
| Taiwan time formatting | 9 files each with its own `new Intl.DateTimeFormat`, and 5 more adding 8 hours by hand | 4 functions in `lib/format.ts` |
| localStorage access | the N5 kanji cards and the tool favorites each had their own store | one `useLocalStorage` hook |
| Reading and writing `.env.local` | 5 scripts each with their own parser | one `env-file.js`, using Node's built-in `util.parseEnv` |
| Radar hourly bar chart | one copy in `/radar`, another in the home page snapshot | one component |

Duplication itself is not a bug; the trouble is **changing one side and forgetting the other**. The share image is an example: when I earlier moved "whose site this is" into the config file, these two were copies, and the name was still hard-coded in them.

## Two real bugs found along the way

### `hour12: false` shows 24:05 at midnight

While consolidating time formatting I noticed that some files used `hour12: false` and others `hourCycle: "h23"`. The live radar had already hit this: in some browsers `hour12: false` shows **24:05** instead of 00:05 at midnight. So everything is now `hourCycle: "h23"`, and there is no `hour12` left in `src/`.

### Tailwind v4's `outline-none` means something different

Tailwind v3's `outline-none` was really a "2px transparent outline"; v4 made it a true `outline-style: none`, and the v3 behavior was renamed `outline-hidden`. The difference matters in Windows **high contrast mode**: a transparent outline gets drawn in a visible system color, while `none` draws nothing, and keyboard users can no longer see where the focus is. There were 29 places on the site, all replaced.

## Small Node 26 things

- fetch timeouts: `AbortController` + `setTimeout` + `finally { clearTimeout }` became a single `AbortSignal.timeout(8000)` (5 places)
- `.mjs` scripts: `path.dirname(fileURLToPath(import.meta.url))` became `import.meta.dirname`
- reading `.env`: my own regex became `util.parseEnv`, which handles quotes, comments and the `export` prefix following dotenv's rules

Some things I deliberately left alone: `[...map.values()].sort()` is already a new array, so `toSorted()` would only add one more copy; Tailwind v4's `rounded-sm` and `shadow-sm` are valid names, just with different sizes than in v3.

## What was deleted

- `TODO.md` and `DONE.md`: the to-dos had long since moved into the admin database, and these two files only held a "moved" note, but the code still had a parser and tests for "if the database is empty, import from TODO.md". Together, over 300 lines gone
- 59 names that were `export`ed but only used inside their own file, and 1 component and 1 type that nobody used at all
- the settings for 5 reminder emails that had already been sent

## An E2E that failed 3 out of 5 runs

After the cleanup I ran E2E, and out of 208 tests exactly one kept failing: "the menu at the top right of a sub-page: clicking a tool changes the page". It passed when run alone, and failed 3 times out of 5 runs of the full suite.

The Playwright trace showed two layers of causes:

1. **The old code was "click again if it did not open".** A click before the sub-page hydrates gets replayed once React takes over; the loop thought it had not opened and clicked again, so the menu opened and then closed
2. **Clicking the link as soon as the menu opened.** At that moment the expand animation was not finished and the link was clipped inside its box, so Playwright first scrolled the page to find it. But the menu has a rule to "collapse when the page scrolls more than 40px", which made the link `inert`, and the click timed out

When the machine is busy, the animation drops frames and takes longer, which is why it only collided when the whole suite ran. I changed two things: click once only after the button has React's `__reactProps` (meaning React has taken over), and click the link only after it is **fully inside the viewport** (`toBeInViewport({ ratio: 1 })`). After the fix, 3 full runs in a row passed.

The site itself had no problem: a real person does not scroll the page within 0.2 seconds. But if I just reran until it went green, the next time something really broke, I could not tell whether it was a real break or the same jitter again.

## Numbers

- 115 files, +453 / −1049 lines (4 more commits are tests, docs, and the remaining time formatting)
- TS 7 type check 0 errors, eslint 0, 505 unit tests, 208 E2E tests
- every file path mentioned in the docs was checked one by one, and stale statements (`force-dynamic`, Node 24, "currently 8 posts") were fixed along with them

---

Author: PINGWEI LI (李秉威, Li Ping-Wei)
Original page: https://kbs0830.com/en/blog/codebase-health-check-node26-tailwind4
