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
Reactのトランジションを覗いてみる
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
ytaisei
January 24, 2025
2.7k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Reactのトランジションを覗いてみる
React Tokyo 第一回 で使用した資料です。
ytaisei
January 24, 2025
More Decks by ytaisei
See All by ytaisei
TanStack Routerを新規プロダクトで1年間運用してみた結果
ytaisei
1
570
Reactを段階的に覗いてみる
ytaisei
3
2.2k
Deep Dive Into React 〜React Fiber Architectureについて〜
ytaisei
2
600
React19で状態管理はどう変わるか
ytaisei
2
250
TanStackで効率的なルーティングとデータ取得を実現
ytaisei
10
2.7k
TanStack Routerで型安全かつ効率的なルーティングを実現
ytaisei
4
2.6k
BunがCommonJSをサポートする理由
ytaisei
2
520
TanStack Router SPA開発の選択肢になるか(+TanStack Query)
ytaisei
2
1.9k
【2023】SWR vs TanStack Query
ytaisei
1
2.3k
Featured
See All Featured
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
440
Facilitating Awesome Meetings
lara
57
7.2k
Writing Fast Ruby
sferik
630
63k
Mobile First: as difficult as doing things right
swwweet
225
10k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
560
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3.1k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
Leo the Paperboy
mayatellez
10
2.4k
A better future with KSS
kneath
240
18k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
580
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
2
6.3k
Transcript
Reactのトランジションを覗いてみる 安井大晟(ytaisei_)
自己紹介 • 株式会社AI Shift ◦ Webフロントエンド ◦ LLMを活用した新規事業 • 社会人1年目
• 2社でBtoBアプリケーション開発 • 2024年は年間12本記事書きました
アジェンダ 1. Reactのレンダリングについて 2. startTransitionについて 3. トランジションとそうでない場合の違い 4. 図解してみる 5.
まとめ
Reactのレンダリングをおさらいする
Reactのレンダリングをおさらいする https://jser.dev/2023-07-14-initial-mount/#1-brief-introduction-on-fiber-architecture Reactは内部でFiber Treeを構築して 差分の更新を最小限に抑えている
4つの実行フェーズ 1. Trigger Phase a. ReactDOMRoot.render()もしくはsetState()がTrigger フェーズの起因 2. Schedule Phase
a. 実行されるタスクに優先順位を設定 する 3. Render Phase a. スケジュールされたタスクを実行し、 新しいFiber Treeを構築してDOMに変更が必要な対象を整理 4. Commit Phase a. 更新対象をDOMに反映
4つの実行フェーズ 1. Trigger Phase a. ReactDOMRoot.render()もしくはsetState()がTrigger フェーズの起因 2. Schedule Phase
a. 実行されるタスクに優先順位を設定する 3. Render Phase a. スケジュールされたタスクを実行し、 新しいFiber Treeを構築してDOMに変更が必要な対象を整理 4. Commit Phase a. 更新対象をDOMに反映 Render Phaseが重たい
startTransitionについて
startTransition API https://ja.react.dev/reference/react/startTransition startTransition 関数を使用すると、 state の更新をトランジションとしてマー クすることができます。
startTransition API https://ja.react.dev/reference/react/startTransition startTransition 関数を使用すると、 state の更新をトランジションとしてマー クすることができます。 トランジションとしてマークするとは?
トランジションとそうでない場合の違い
Reactのレンダリングをおさらいする トランジションとしてマークされていない場合: デモのリンク トランジションとしてマークされた場合: デモのリンク 非常に重たいタブを配置
トランジションとしてマークされていない場合 Reactはレンダリングが完了されるまで 同期的に実行するため、 UIがブロッキングされてしまう。
トランジションとしてマークされた場合 実行されるタスクが細切れに分割され、 ユーザのイベントを受け付けることができる
図解してみる
トランジションとしてマークされていない場合
トランジションとしてマークされた場合 タスクが細かく分割されている
まとめ
まとめ 1. startTransition 関数を使用すると、 state の更新をトランジションとしてマーク することができる 2. トランジションとしてマークされた 更新タスクは優先度が低くなる
3. 低い優先度のタスクは 一定の間隔でタスクを中断 し、中断した時点から再度 MacroTaskに登録してタスクを再開する
まとめ 1. startTransition 関数を使用すると、 state の更新をトランジションとしてマークすることができる 2. トランジションとしてマークされた更新タスクは優先度が低くなる 3. 低い優先度のタスクは一定の間隔でタスクを中断し、中断した時点から再度
MacroTaskに登録してタスクを再開する その結果重たいstate更新の処理中もユーザのイベントを受け付けることができる
ご清聴いただきありがとうございました! 詳しい内容はこちらまで