Writing
I write short notes on tools and habits that help with day-to-day engineering.
2025
- Write and run tests with node:testWrite a test with node:test and node:assert, run it with node --test, read the failure diff, and see which file names the runner finds.
- Web Push for iOS Home Screen appsEnable Web Push in an iPhone Home Screen web app by preparing its service worker and subscribing on a tap.
- Debug a failing Playwright test with UI modeInspect the page before and after each action in a failing Playwright test using UI mode or a trace file.
- Pick moduleResolution by what runs your codeChoose a resolution mode based on whether Node or a bundler resolves the imports you write.
- Standard decorators in TypeScriptWrite a standard method decorator in TypeScript, compile it to JavaScript and run it in Node.
- const type parameters keep literal typesUse a const type parameter with a readonly constraint to infer literal tuples from inline arrays.
- Delete the effect that copies props into stateCompute a filtered list during render so it follows the current props without an effect or a second state update.
- Make a card respond to its containerUse a container size query to keep the same card stacked in a sidebar and side by side in a wide column.
- Jump between directories with zoxideJump to a directory with z and inspect the scores that zoxide uses to choose among matches.
- Choose Promise.all or allSettledUse Promise.all when one failure should fail the whole step and allSettled when partial results are fine, then read each result by its status.
- Restart a Node server with --watchRun node --watch to restart a server when its entry file or any module it imports changes, and see how it handles a crash.
- Lint staged files with lefthookSet up a pre-commit hook with lefthook that runs lint and format checks in parallel on the paths you staged.
- Split state and dispatch into separate contextsSplit state and dispatch into separate React contexts to spare dispatch-only consumers from state updates.
- Fix mobile 100vh with dvh unitsUse dvh to size a mobile section around browser toolbars, or svh to keep its minimum height stable.
- Object.hasOwn replaces hasOwnPropertyUse Object.hasOwn to check for own properties on null-prototype objects or data that shadows hasOwnProperty.
- Show the base in conflicts with zdiff3Use zdiff3 conflict markers to see the merge base and trim matching lines from the edges of a conflict.
- Key remapping with as in mapped typesUse as in a mapped type to derive getter names and event handlers from the keys of an object type.
- Write effects that survive Strict Mode double-runReturn a cleanup function so a subscription survives Strict Mode's extra development setup cycle.
- Generate hydration-safe IDs with useIdUse useId to associate labels and inputs with matching IDs on the server and during hydration.
- Write a one-page decision recordUse a short Markdown decision record to preserve the options you considered and the trade-offs behind your choice.