From b54f88939d932c0baa43f07942803901350630fd Mon Sep 17 00:00:00 2001 From: Xe Iaso Date: Thu, 19 Mar 2026 13:39:09 +0000 Subject: [PATCH] feat(web): port PoW challenge page from vanilla JS to Preact Replace the imperative DOM manipulation in web/js/main.ts with a declarative Preact component (web/js/main.tsx). The project already uses Preact for the timed-delay challenge (lib/challenge/preact/), so this aligns the PoW challenge with the existing codebase direction. Convert web/js/main.ts to a Preact TSX component. The worker orchestration layer (web/js/algorithms/fast.ts) stays untouched -- it is already cleanly separated and works via a Promise API. web/js/main.ts -> web/js/main.tsx: - Phase-based state machine (loading -> computing -> reading/error) replaces scattered imperative DOM updates. - Worker lifecycle managed in useEffect; progress callback drives state setters for speed and progress percentage. - Speed updates remain throttled to 1 second intervals. - i18n functions (initTranslations, t(), loadTranslations) kept as module-level state -- no need for React context in a single- component app. - The
section stays in the templ file as server-rendered HTML; the Preact component tracks its toggle state via useRef. - Uses esbuild automatic JSX transform (--jsx=automatic --jsx-import-source=preact) instead of classic pragmas. web/build.sh: - Add js/**/*.tsx to the glob so esbuild bundles TSX files. - Pass --jsx=automatic --jsx-import-source=preact for .tsx files. web/tsconfig.json (new): - IDE-only config (noEmit) so TypeScript understands Preact JSX types for editor diagnostics and autocompletion. lib/challenge/proofofwork/proofofwork.templ: - Replace individual DOM elements (img#image, p#status, div#progress) with a
Preact mount point containing server-rendered fallback (pensive image + loading text). - Keep
,