Engineering note · Clonernews
Rebuilding Clonernews without React
- Project
- Clonernews — Internal project, Zone01 Kisumu
- Issue
- PR #7: Feat/vanilla js
- My role
- Author of PR #7 (rewrite, network layer, utilities)
- Stack
- HTML · CSS · JavaScript (ES modules) · Hacker News API
- Status
- Merged 6 Oct 2026
The problem
Clonernews is a reader for the public Hacker News API: stories, jobs, polls, comments and live updates. My pair partner and I started it as React components (.jsx) with hooks for state. But the repository had no package.json, no index.html and no build tool. Nothing installed React or compiled the JSX, so the app could not run in a browser as it stood.
What I did
I removed React in three steps, so each commit stayed small enough to review.
- I replaced each component with a plain function that returns DOM elements, built with a small
h()helper. Inline styles moved into CSS classes. - I renamed
hooks/tostate/and rewrote the store and the debounce and throttle helpers without React. - I rebuilt the app as
index.html,css/style.cssand seven ES modules injs/. There is no build step; any static server works.
The API sends one request per item, so a feed page means many requests. I wrote js/api.js to keep that load low:
- An item cache with a 3,000-entry limit, evicting the least recently used. Feed id lists are cached for 30 seconds.
- In-flight dedupe: identical requests share one promise.
getItems()fetches with at most 8 requests at a time and keeps the input order. A failed item comes back asnull; it only throws if every request failed.- Retries with exponential backoff and jitter, after an 8-second timeout. Only network errors, 429 and 5xx are retried, since other 4xx errors will not fix themselves.
Live data polls every 5 seconds. It stops while the tab is hidden and refreshes as soon as the tab is visible again. Job postings change rarely, so they are checked every sixth tick. Items reported as changed are dropped from the cache.
In js/utils.js, debounce waits for a pause, which suits the filter box (250 ms). throttle runs at once, then at most once per interval, and still runs the last call so the final event is not lost:
if (remaining <= 0) { clearTimeout(timer); run(); }
else if (!timer) { timer = setTimeout(run, remaining); }
It limits infinite loading (800 ms) and the back-to-top scroll handler (150 ms).
How I checked it
The project has no automated tests, so I checked the design against the code and the API.
- The old tree had no
package.jsonorindex.html. That confirmed the React version had no way to run. - I made the retry rule explicit in
isRetryable(), so a 404 fails at once instead of retrying three times. - Polling checks
document.hiddenboth before a request and before scheduling the next one, so a hidden tab does not keep a timer going. - My pair partner's next two PRs (#8 and #9) built on the rewrite. They changed the feed, live and render modules but did not need to touch
api.jsorutils.js.
What I learned
A framework is not free. Without a build set-up, React only added code that could not run. For a small reader, plain modules and a DOM helper were enough. The work that mattered most was the network layer. Being polite to a shared public API comes down to a few rules: cache, share requests, limit concurrency, back off and stop when nobody is looking.