Skip to content

feat(views): convert pages.ts to Hono JSX components (0X0-15) - #8

Merged
catoncat merged 2 commits into
mainfrom
1x02790/0x0-15-jsx
May 11, 2026
Merged

feat(views): convert pages.ts to Hono JSX components (0X0-15)#8
catoncat merged 2 commits into
mainfrom
1x02790/0x0-15-jsx

Conversation

@catoncat

@catoncat catoncat commented May 11, 2026

Copy link
Copy Markdown
Owner

M1 收官 / 5 of 5. Closes 0X0-15.

What

Split the monolithic src/pages.ts (383 lines of string-concat HTML) into per-view TSX files under src/views/:

  • Layout.tsx, Header.tsx, Footer.tsx, Promo.tsx — shared shells
  • EditorPage.tsx, ResultPage.tsx, NotePage.tsx, InterstitialPage.tsx, EditNotePage.tsx, NotFoundPage.tsx — one file per route
  • views/index.ts — barrel re-export (one-line drop-in for src/index.ts)

Approach

JSX (hono/jsx, automatic runtime) handles the structural markup. Large inline <style> and <script> blocks remain as string constants and are injected via raw() from hono/html, so we don't have to escape every quote/brace in 2 KiB CSS or interpolate prefillTtl into the editor's JS by hand.

Each page function still returns a Response via the shared html() helper, preserving the existing SECURITY_HEADERS + cache-control behavior. No call-site changes in index.ts other than swapping the import path.

Verification

  • npx tsc --noEmit — clean
  • npx vitest run — 20/20 (10 new snapshot tests in test/views.test.ts lock the new baseline)
  • npx wrangler deploy --dry-run — 202.78 KiB / gzip 53.14 KiB
  • wrangler dev + curl / — 200 OK, correct title, valid HTML shell

Notes

  • tsconfig: added "jsx": "react-jsx", "jsxImportSource": "hono/jsx"
  • Snapshots set a new baseline (not byte-identical with the old string output — same DOM/visuals, stable across future edits)

Summary by cubic

Converted the monolithic src/pages.ts (string-built HTML) to Hono JSX components under src/views/, one file per route. Completes 0X0-15 and preserves existing behavior, routes, and headers.

  • Refactors
    • Split into TSX files: shared Layout, Header, Footer, Promo; pages EditorPage, ResultPage, NotePage, InterstitialPage, EditNotePage, NotFoundPage.
    • Kept large inline CSS/JS as strings and inject via raw() from hono/html.
    • Added shared Layout; pages still return Response via html() with existing security headers and cache behavior.
    • Swapped src/index.ts import to ./views/index.js barrel.
    • tsconfig: set "jsx": "react-jsx" and "jsxImportSource": "hono/jsx".
    • Added vitest snapshot tests for all views (10 snapshots) to lock HTML output.
    • No API or route changes.

Written for commit 545f812. Summary will update on new commits.

catoncat added 2 commits May 11, 2026 09:44
… (0X0-15)

Split the monolithic src/pages.ts into per-view TSX files under src/views/:
  Layout, Header, Footer, Promo (shared shells)
  EditorPage, ResultPage, NotePage, InterstitialPage, EditNotePage, NotFoundPage

JSX handles the structural markup; large inline CSS/JS blocks stay as string
constants and are injected via raw() from hono/html so they don't get escaped.
Each page function still returns a Response built via the shared html() helper,
preserving security headers and status codes.

Adds vitest snapshot coverage for all six views (test/views.test.ts), locking
the new baseline. tsc clean, vitest 20/20 (10 new snapshots), wrangler
deploy --dry-run 202.78 KiB. Home page renders 200 OK with identical title and
shell structure.

Closure of M1 milestone (5/5).
@catoncat
catoncat merged commit dcb7e08 into main May 11, 2026
1 of 2 checks passed
@catoncat
catoncat deleted the 1x02790/0x0-15-jsx branch May 11, 2026 02:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant