feat(views): convert pages.ts to Hono JSX components (0X0-15) - #8
Merged
Conversation
… (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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 undersrc/views/:Layout.tsx,Header.tsx,Footer.tsx,Promo.tsx— shared shellsEditorPage.tsx,ResultPage.tsx,NotePage.tsx,InterstitialPage.tsx,EditNotePage.tsx,NotFoundPage.tsx— one file per routeviews/index.ts— barrel re-export (one-line drop-in forsrc/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 viaraw()fromhono/html, so we don't have to escape every quote/brace in 2 KiB CSS or interpolateprefillTtlinto the editor's JS by hand.Each page function still returns a
Responsevia the sharedhtml()helper, preserving the existingSECURITY_HEADERS+ cache-control behavior. No call-site changes inindex.tsother than swapping the import path.Verification
npx tsc --noEmit— cleannpx vitest run— 20/20 (10 new snapshot tests intest/views.test.tslock the new baseline)npx wrangler deploy --dry-run— 202.78 KiB / gzip 53.14 KiBwrangler dev+curl /— 200 OK, correct title, valid HTML shellNotes
"jsx": "react-jsx","jsxImportSource": "hono/jsx"Summary by cubic
Converted the monolithic
src/pages.ts(string-built HTML) to Hono JSX components undersrc/views/, one file per route. Completes 0X0-15 and preserves existing behavior, routes, and headers.Layout,Header,Footer,Promo; pagesEditorPage,ResultPage,NotePage,InterstitialPage,EditNotePage,NotFoundPage.raw()fromhono/html.Layout; pages still returnResponseviahtml()with existing security headers and cache behavior.src/index.tsimport to./views/index.jsbarrel.tsconfig: set"jsx": "react-jsx"and"jsxImportSource": "hono/jsx".vitestsnapshot tests for all views (10 snapshots) to lock HTML output.Written for commit 545f812. Summary will update on new commits.