🔍 inp.works

メインスレッドのブロック:ハンドラーが動く前から大きなinput delay

何が起きているか

input delayは、ユーザーのクリックからイベントハンドラーが開始するまでの時間です。ハンドラー自体は完璧に速くても、メインスレッドが長いタスク(ハイドレーション、アナリティクス初期化、データ解析のタイマー)の途中だと、イベントはそのタスクが終わるまで列で待ちます。

これはハンドラーでは直せない唯一のINPフェーズです。原因はたまたま実行されていた別のコードだからです。

見分け方

直し方

問題

// at page load: one 800 ms task — every click during it waits
initAnalytics()
buildSearchIndex(allProducts)
prefetchRecommendations()

修正

initAnalytics()
await scheduler.yield()                  // events can run between steps
buildSearchIndex(allProducts)
requestIdleCallback(() => prefetchRecommendations())
サイトを無料でスキャン →
Advertise here