Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Dive Into Single Fetch
Search
YUMOTO Michitaka
September 25, 2024
Technology
310
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Dive Into Single Fetch
Remix Meet Up Tokyo#2
YUMOTO Michitaka
September 25, 2024
More Decks by YUMOTO Michitaka
See All by YUMOTO Michitaka
Short Introduction for Kysely
gothedistance
1
520
クラフトマンシップ(職人魂)を湾岸MIDNIGHTから学ぼう / Learn Craftsmanship from Wangan Midnight
gothedistance
0
410
プロ野球をデータモデリングしてみたら沼だった件 / Baseball ERD Modeling to be obsessed
gothedistance
2
930
フロントエンド開発スタイルの変遷と、私がFlutterにハマったわけ
gothedistance
8
15k
ITプロジェクトのはじめ方 / How to work around software project
gothedistance
28
150k
私がITプランナーを志すようになった理由、そして、目指していること / bpstudy142_why_i_wanna_be_a_it_plannner
gothedistance
1
990
ITプランナーの必要性を小一時間問い詰めたい / Why We need IT-Planner.
gothedistance
0
14k
IT企画をちゃんとやりたい#01 ガイダンス資料 / IT Planning do well_01
gothedistance
0
6.5k
bpstudy_127
gothedistance
0
610
Other Decks in Technology
See All in Technology
AgentCoreで実践するハーネスエンジニアリング
yakumo
1
190
【ゲームメーカーズスクランブル2026】『Shadowverse: Worlds Beyond』UIとアニメーションで実現する最高のユーザー体験を叶えるプロトタイピング
cygames
PRO
1
710
AIに書かせて、プラットフォームで縛る ― EKSプラットフォームで実践した責任境界と権限設計
elmodev09
1
1.1k
Argo CDとAtlantisで実現するインフラ管理のセルフサービス化──小規模SREチームで支えるプラットフォーム
cassius7
0
270
行動するAIのためのオントロジー | DevRev — Encraft #26.pdf
dvrv_tknrszk
2
670
認知負荷を吸収し、プロダクトをまたぐPR Preview基盤の設計事例
taiki45
2
570
Execution in the Kingdom of Agents: Reflections on Abstraction and Complexity
bcantrill
0
680
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
16
120k
AI駆動開発で仕様はどこまで書くべきか? ― 人とAIの責務境界から考える開発プロセスの実践
takahiromatsui
1
290
AI臭い文章とは何なのか
nasuvitz
38
77k
形式手法を使って仕様をコーディングしよう
mikanichinose
0
160
企業の現実世界をグラフで写し取る
sansantech
PRO
0
240
Featured
See All Featured
Joys of Absence: A Defence of Solitary Play
codingconduct
1
530
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.5k
Paper Plane
katiecoart
PRO
4
53k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
440
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Marketing to machines
jonoalderson
1
5.8k
How to build a perfect <img>
jonoalderson
1
6.1k
Mobile First: as difficult as doing things right
swwweet
225
10k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
540
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2.1k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
510
Transcript
Dive into Single Fetch Remix Tokyo Meetup #2 (2024.09.25) @gothedistance
Self Introduction ゆもとみちたか@1979.11.12 X: @gothedistance GoTheDistanceというブログを書いています 新卒SIer→Webエンジニア→2016年独立して9年目 Javaエンジニア→PHP/Python→Flutter→Remix/TS 東京ヤクルトスワローズのファンです! 2
Agenda Single Fetch 概説 ドキュメントリクエストとクライアントサイドリクエスト turbo-stream の活用 Middleware の実装を追いかけた結果wwwwww 3
Single Fetch Just because unstable, doesn’t mean very buggy. 個人的に最も大きなRemixの改善点
4
Single Fetch(Fetchをするのはたった1つ) 2.9から導入されたRemixのリクエスト処理 2.9以前では・・・ ドキュメントリクエストの場合は GET /about/me をfetchして、該当する loaderが実行される。 クライアントサイドでページ遷移する場合、
GET /about と GET /about/me に対して、個別のリクエストを飛ばしていた。 loader個別にリクエストが飛んでしまうと、MiddlewareやServer Context などの実装に支障がががが。個人的にRemixの最もネガポイント。 Single Fetchでは、クライアントサイドでのページ遷移において も、ドキュメントリクエストと同様に処理される。ナイス〜。 5
turbo-streamによるdecode/encode JSON.stringify でデータをシリアライズしていた。E2Eで型安全が できるのに、DateがStringになるのは微妙といえば微妙。 turbo-stream によって、JavaScriptのオブジェクトがByteStreamと して渡される(そういう実装に読めた)為、デコード時に型が保てる ようになった。 Promiseを返す時は defer
でStreamを返し、そうでない時は json で シリアライズする実装が、 turbo-stream によってStreamに統一。 Single FetchがStableになると、 json と defer は非推奨になる気が する。必然性がなくなるから。 6
Promiseを返して遅延ロード 自分のようなReact初心者は、 Promise を返すという発想が衝撃。 export async function loader({params}: LoaderFunctionArgs) {
const reviewsPromise = db.getReviews(params.productId); return { reviews: reviewsPromise }; } export default function Product() { const { reviews } = useLoaderData<typeof loader>(); return ( <Suspense fallback={<ReviewsSkeleton />}> <Await resolve={reviews}> {(reviews) => <ProductReviews data={reviews} />} </Await> </Suspense> )} 7
お手軽バックグラウンドタスク レスポンスを返す処理と同期せず、バックグラウンド・タスクが実 行できる。Pythonだと明示的にスレッド立ててやっていた記憶。 export async function action({params}: ActionFunctionArgs) { //
バックグラウンドで実行される setImmediate(() => sendmail(params)); // こっちは即座にレスポンスを返す return { success: true }; } export default function Product() { const { success } = useActionData<typeof action>(); return ( {success ? <p>メール送信しました</p> : <p>メール送信中</p>} )} 8
Middleware Support Single Fetchだけでは実現できない 9
Middlewareのロードマップは不透明に見える リクエスト・レスポンスの前処理・後処理をグローバルに行うため の仕組み。FastAPIなどのWAFをお使いの方でお馴染み。 Remixは 全てのloaderを並行に実行する ポリシーのため、loaderが呼び 出される前にMiddlewareが実行される必要があると思われる。 /a /a/b /a/b/c
のルートで、 /a/b/c に対してリクエストが発行さ れると、ルートから並行に /a /a/b /a/b/c のloaderが実行され る。 /a の評価を待つことはない。 loaderの処理を待つとシーケンシャルになるため、パラレルが売り のRemixの看板に偽りがあることに... 10
entry.sever.tsxをゴニョれば・・・? ドキュメントリクエストでは通るけど、クライアントサイドのリク エストでは handleRequest が実行されない。 11
HTTPサーバで頑張るぞい Remixの loader/action の中でMiddlewareを頑張るのは難しいが、 Expressのレイヤーでゴニョるならいけるんじゃないか? Single FetchによってFetchする対象が1個のみになったのだから! 月曜日の夜にそれに気づいた私は、あわてて情報を探しました Remix flat
Route でRemix Devを救った killman 氏が、カスタムの express ビルドプラグインを公開していた。 https://github.com/kiliman/remix-express-vite-plugin/ 上記のプラグインの解説動画: https://www.youtube.com/watch? v=_dbMs9D5kdQ 12
次回予告(出オチ) remix-express-vite-plugin を使って Middleware を実装してみた zennあたりに来月公開予定 13