Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Honoとhtmx
Search
Yusuke Wada
March 15, 2024
Programming
6
1.6k
Honoとhtmx
Yusuke Wada - 2024/3/15
Ya8 2024 - ヤパチー 令和六年最新版(仮)
Yusuke Wada
March 15, 2024
Tweet
Share
More Decks by Yusuke Wada
See All by Yusuke Wada
JS RPCを理解する
yusukebe
5
610
Cloudflare Workersの環境を再現することについて
yusukebe
5
890
Hono v4
yusukebe
11
4.7k
Hono v3 and v4
yusukebe
4
3.7k
The power of Web-standards
yusukebe
4
1.7k
実践エッジユースケース
yusukebe
7
2.1k
Mojoliciousでつくる! Webアプリ入門
yusukebe
0
390
どこでも動くWebフレームワークをつくる
yusukebe
17
28k
Hono v3 - Do Everything, Run Anywhere, But Small, And Faster
yusukebe
4
800
Other Decks in Programming
See All in Programming
CSC305 Lecture 01
javiergs
PRO
1
140
App Router 悲喜交々
quramy
7
370
ECS向けのドリフト検知機構を実装してみた
tkikuc
0
270
モジュラモノリス、その前に / Modular monolith, before that
euglena1215
6
590
◯◯エンジニアになった理由
gessy0129
PRO
0
610
Infrastructure as Code でセキュリティを楽にしよう!
konokenj
5
1.4k
ACES Meet におけるリリース作業改善の取り組み
fukucheee
0
120
[PHPカンファレンス沖縄2024]「無理なくできるだけ安全に」テストもないレガシーコードをリファクタリングするテクニック
ikezoemakoto
3
110
Remix × Cloudflare Pages × Sentry 奮闘記 / remix-pages-sentry
nkzn
1
370
Subclassing, Composition, Python, and You
hynek
3
110
AWS認定資格を受験するにあたり、気づいたこと・実践していたことのまとめ
satoshi256kbyte
1
120
上手に付き合うコンポーネントテスト
quramy
3
1.2k
Featured
See All Featured
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
4
99
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
249
21k
Six Lessons from altMBA
skipperchong
26
3.4k
Ruby is Unlike a Banana
tanoku
96
11k
Music & Morning Musume
bryan
46
6.1k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
45
4.9k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
327
21k
StorybookのUI Testing Handbookを読んだ
zakiyama
26
5.1k
Fontdeck: Realign not Redesign
paulrobertlloyd
81
5.2k
How GitHub Uses GitHub to Build GitHub
holman
473
290k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
22k
The Pragmatic Product Professional
lauravandoore
31
6.2k
Transcript
Honoͱhtmx Yusuke Wada - 2024/3/15 Ya8 2024 - Ϡύνʔ ྩ࠷৽൛(Ծ)
Honoͱhtmxʹ͍ͭͯ͠·͢ 1. αʔόʔαΠυJSXʹ͍ͭͯ 2. Hono+htmxελοΫʹ͍ͭͯ 3. HonoͷClient Componentsʹ͍ͭͯ
1. αʔόʔαΠυJSXʹ͍ͭͯ
HonoʹϏϧυΠϯͷJSX͕͋Δ • `hono/jsx` • ࠷ۙ·ͰαʔόʔαΠυͷΈͩͬͨ • React͕ϑϩϯτΤϯυ͔ΒͰ͖ͯͨͷͰαʔόʔαΠυ͚͍ͩ͠ͱࢥ͏ • ͜ͷJSX͕htmxͱ૬ੑ͕͍͍ͱऔΓࠫଡ͞Ε͍ͯΔ
hono/jsxͷྺ࢙1 • ࠷ॳHTMLग़ྗͰMustache͕͋ͬͨ
hono/jsxͷྺ࢙2 • ଞͷςϯϓϨʔτΤϯδϯʢHandlebarsɺejsͱ͔ʣΛೖΕ͔ͨͬͨ • ͔͠͠eval͕͑ͳ͍ ← Τοδɺͱ͍͏͔Cloud fl are Workersͱ૬ੑ͕ѱ͍
• micro-template.js Λ͏ͱ͢Δ…
hono/jsxͷྺ࢙3 • @usualoma͞Μ͕JSXΛఏҊ
hono/jsxͷྺ࢙4 • 2022-06-05ੜʂ • 2022-07-10ʹMustache Middleware͕ഇࢭ
hono/jsxͷྺ࢙5 • ͦͷࠒ͔ΒHotwireͷΛ͍ͩͯ͠Δ • ʮJSXͷSSRͱHotwireͷΘͤΑͦ͞͏ɻHono+JSXReactΑΓRailsͬΆ͍ ͔ΒɺHotwire૬ੑ͍͍ͱࢥ͏ʯ
None
`hono/jsx` • JSXJavaScriptؔͷγϯλοΫεγϡΨʔ • jsx(component, props, children) Λݺͼग़͢ • `hono/jsx`stringΛDOMͰͳ͘stringΛग़ྗ͢Δ
• ReactͷrenderToString()૬͕ͳͯ͘จࣈྻʹͳΔ • ͳͷͰԼͷίʔυಈ͘
͜Ε͚ͩͰॻ͚Δ
ίϯϙʔωϯτॻ͚ΔͷͰ͍͍͍͚ͩͨΔ
`hono/jsx`ศརʂ
2. Hono+htmxελοΫʹ͍ͭͯ
htmx͕Γ্͕ΔͱHono+htmxʹ͕ • ελοΫʹͳΔ ← ࠷ۙͨΒͱελοΫʹ͕ͨ͠Δ • ྫ:T3 Stack = Next.jsɺtRPCɺTailwind
CSSɺTypeScript… • HonoʢಛʹJSX͕͋Δ͔ΒʣͱhtmxͷελοΫ
6࣌ؒલʹʮCHHATʯͳΔελοΫʂ
CloudflareͱͷελοΫͷݩ
ϒϩάॻ͍ͨʮHono + htmx + Cloudflare is a new stackʯ •
ελοΫ • Hono + ΈࠐΈJSX • htmx • Zod • Tailwind CSS • Cloud fl are Workers • Cloud fl are D1
Zod + Zod Validator͍͍Α
͜ͷTODOΞϓϦ͕100ߦͰͰ͖Δ
MPAͰΤοδͰಈ͔͍ͤͷͰSPAΈ͍ͨͳಈ͖͢Δ
ΫϥΠΞϯτ͕ඞཁͳ͍ • ΫϥΠΞϯτϏϧυ͕ඞཁͳ͍ • wrangler/bun/denoίϚϯυ͚ͩͰ͍͚Δʂ • ΫϥΠΞϯτΛؚΊΔͱͲ͏ͯ͠Ϗϧυ͠ͳ͍ͱ͍͚ͳ͍ • ΊͪΌͪ͘Όϙʔλϒϧʂ
Hono+htmx ͍͍Αʂ
3. HonoͷClient Componentsʹ ͍ͭͯ
htmx͍͍Μ͚ͩͲ… • ઌఔͷBlogͭ͘Δͷʹۤ࿑ͨ͠ • ঢ়ଶΛ࣋ͭͷ͕Ͱ͖ͳ͍ => Alpine.jsΛ͏͜ͱʹͳΔ • αʔόʔαΠυJSXͱૉͷJavaScript͕ΊͪΌͪ͘Ό૬ੑѱ͍ •
ΠϯϥΠϯͰॻ͘͜ͱʹͳΔɺͦΕ͔֎෦ϑΝΠϧ
͜͏͍͏ͷ͕ਏ͍
HonoͷJSXͰΫϥΠΞϯτΛαϙʔτ • Client Components => `hono/jsx/dom` • useState/useE ff ect/useRef/useͳͲReactޓͷϑοΫΛࡌ
• αʔόʔαΠυΘͣͱ;ͭʔʹΫϥΠΞϯτ͚ͩͰಈ͘
DOMʹϋΠυϨʔτͰ͖Δ
HonoXͱ͏ͱڧྗ • HonoXBYOR͚ͩͲσϑΥϧτhono/jsx • IslandsίϯϙʔωϯτΛSSR/ϋΠυϨʔτ͢Δ • αʔόʔαΠυͰSSRͯ͠ɺΫϥΠΞϯτͷDOM͕ೖɺΠϯλϥΫςΟϒ ʹͳΔ • ඞཁͳϖʔδ͚͔ͩ͠JavaScript͕৴͞Εͳ͍
• SEOʹ༗རͩ͠ɺͪΒ͖͕ͭͳ͍
Honoͷ߹ αʔόαΠυͱΫϥΠΞϯτ͕͍ۙͱ ͞Βʹਪ͠ϙΠϯτ͕͋ͬͨ
RPC-mode • αʔόʔͱΫϥΠΞϯτؒͰAPIͷSpecΛTypeScriptͷܕͱͯ͠ڞ༗͢Δ • Islandsͱ͍͑ͲɺΫϥΠΞϯτ<=>αʔόʔͷAPIݺͼग़͠ൃੜ͢Δ • ͦ͜ͰHono RPCͰ͢Α
Next.jsͷதͰHono • ࣮Next.jsͷAPIͷதͰHono͕ΘΕΔέʔε͕͋Δ • ͦΕ͜ͷRPC-modeΛ͏ͨΊɺಉ͡Α͏ͳ͜ͱ͕HonoXͰΑΓ૬ੑྑ͘ Ͱ͖Δ ͓·ͪΐͬͱ͓͍ͱ͍ͯਪ͠͞Ε͍ͯΔ
app/routes/index.tsx • HonoXͷϧʔτʹClassical appॻ͚Δ
app/islands/todo.tsx • `hono/client`Λ͏
`hono/jsx/dom` + HonoX ΘΓͱ͍͍
ࠓߟ͍͑ͯΔ͜ͱ • ͱΓ͋͑ͣαεςʔλεͳͷͰυοάϑʔσΟϯά͢Δ • Islands/Client Components/ͪΐͬͱෆ҆ఆ͔͚ͩͲSSR҆ఆ͍ͯ͠Δ • SSGϒϩάΛͭ͘Δͷʹศརʢhono/jsx/dom͡Όͳ͍͚Ͳʣ
package by feature • σΟϨΫτϦʹ͢Δ͔͓͍ͱ͍ͯྑͦ͞͏ʢͳؾ͕ͯ͠Δʣ
Islands͚ͩͰۙ͘ʹ͋Δͱ͍͍͢ • ͜ΜͳͷͲ͏ͩΖ͏͔
Α͍͖ͯ͘͠· ͢
·ͱΊ 1. αʔόʔαΠυJSXʹ͍ͭͯ 2. Hono+htmxελοΫʹ͍ͭͯ 3. HonoͷClient Componentsʹ͍ͭͯ React/Next.jsͱҧ ͏ΞϓϩʔνͰ໘ന͍
ͬͯΈ͍ͯͩ͘͞
͓͠·͍