Writing
I write short notes on tools and habits that help with day-to-day engineering.
2025
- How stale-while-revalidate worksUse Cache-Control to set how long a cache may serve a stale response while refreshing it in the background.
- Control specificity wars with @layerUse CSS cascade layers to order normal declarations before specificity and see how important declarations reverse that order.
- satisfies vs a type annotation in TypeScriptUse satisfies to check a route table while retaining its actual keys and HTTP method types.
- Shut down a Node HTTP server cleanlyHandle SIGTERM in Node, give in-flight HTTP responses time to finish and close connections that pass the deadline.
- Find a bad commit with git bisect runUse a test script with git bisect run to find the first bad commit and skip revisions the script cannot test.
- Make bash scripts fail fastUse set -euo pipefail to catch common Bash failures and learn where errexit has exceptions.
- Fix fetch race conditions inside useEffectA slow earlier request can overwrite a newer result. Ignore the stale response with a cleanup flag, or cancel it with an AbortController.
- Test debounce and retries with fake timersUse Vitest fake timers to assert debounce and promise-based retry behaviour without waiting on the real clock.
- Use git switch and restore instead of checkoutUse git switch to change branches and git restore to recover or unstage files, even when a branch and file share a name.
- Send 103 Early Hints before the HTMLStart CSS and font fetches during server think time by sending a 103 Early Hints response with Link preload headers from Node.
- Stop unions splitting in conditional typesWrap both sides of a conditional type in tuples to check a union as a whole.
- Ship a Node image without devDependenciesUse a two-stage Dockerfile to compile in a build stage and copy only dist into a runner stage that installs production dependencies.
- Format "3 days ago" with Intl.RelativeTimeFormatUse Intl.RelativeTimeFormat to write labels such as "3 days ago" and "yesterday" in the reader’s locale.
- Give estimates as rangesGive a range, name what could move it, and say when you’ll update the estimate.
- Exhaustive switch with a never checkAdd a never check to a switch so TypeScript names any union member the switch leaves unhandled.
- Top-level await and module load orderTrace how top-level await delays dependent modules while an independent branch of the import graph runs.
- Fix the controlled input warning in ReactKeep a React text input controlled from its first render by giving it a string value.
- Record a Playwright test with codegenPoint npx playwright codegen at your app, click through it, and save the recording as a first test you can run and edit.
- String unions vs enums vs as const objectsUse a string union for type checking and derive it from an as const object when you also need the values at runtime.
- Responsive card grid without media queriesLet CSS Grid choose how many columns fit and use auto-fit to collapse columns that have no cards.