useScrollPosition re-attaches its scroll listener on every frame while scrolling
メンテナーはふだん 2 日以内に返信
@ayushgade06 がすでに取り組んでいます。
2026年9月29日 から。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 78/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- javascript, react
- 領域
- frontend, performance
調査の方向性
src/components/Animated-steps-list/scroll-position.js から始め、useScrollPosition エフェクトが ticking をどのように保存し、scroll リスナーをバインドしているかを調べます。コンポーネントのライフタイム全体にわたってリスナーをアタッチしたままにし、アニメーションフレームのゲートには state を使わないブックキーピングを使用し、scroll 位置は state に保持します。React DevTools またはリスナーのインストルメンテーションを使って、スクロール中にレンダーと追加/削除のサイクルが毎フレーム発生しなくなったことを確認します。
索引モデルが issue の本文から書いたものです。
説明
Description
The useScrollPosition hook in [src/components/Animated-steps-list/scroll-position.js](https://github.com/layer5io/layer5/blob/master/src/components/Animated-steps-list/scroll-position.js) drives the scroll-scrubbed terminal animation on the [Meshery Getting Started page].
The hook uses requestAnimationFrame throttling with a ticking flag, but the flag is stored in React state and included in the effect's dependency array.
Because ticking changes from false to true and back on every animation frame:
- The state changes trigger unnecessary React re-renders.
- The effect re-runs whenever
tickingchanges. - Its cleanup removes the scroll listener and its setup immediately adds it again.
During scrolling, this can cause the listener to be detached and re-attached roughly 60 times per second, creating unnecessary main-thread work during an interaction where responsiveness matters.
This does not currently cause visible breakage. It is a performance and correctness issue.
This is a reusable hook in the general-purpose components/ folder with the generic name useScrollPosition. If it is reused elsewhere in the future, the same listener thrashing and unnecessary re-renders would be introduced automatically. Fixing it now prevents the issue from silently spreading to other pages.
Expected Behavior
The scroll listener should:
- Be attached once when the component mounts.
- Remain attached throughout the component's lifetime.
- Be removed once when the component unmounts.
- Throttle updates to roughly one per animation frame without causing extra re-renders.
- Use a passive scroll listener.
Proposed Changes
Both options address the same two issues:
- Change the effect dependency array to
[]so the listener is not re-bound when the throttle flag changes. - Remove
tickingfrom React state so internal throttle bookkeeping does not trigger re-renders.
The scroll position should remain in state because the UI depends on it.
Option 1: Local Variable
Use a plain variable scoped inside the effect to track whether an animation-frame update is already scheduled.
The variable changes synchronously, causes no re-render, and is discarded when the effect is cleaned up.
Option 2: useRef
Store the ticking flag in a useRef instead of state.
A ref can be updated synchronously without triggering a re-render, making it suitable for a throttle gate while keeping the flag explicitly named.
If we want a lazy fix we can go with option 1 or else option 2
Reasoning
The dependency array is the main cause of the listener thrashing. Since ticking changes every frame, including it as an effect dependency causes the effect's cleanup and setup to run repeatedly.
Using [] makes the listener bind once for the component's lifetime.
The throttle flag also does not belong in state because it is internal bookkeeping that the UI does not depend on. State changes trigger renders, while a local variable or ref updates synchronously so the next scroll event immediately sees the throttle state.
Impact
This change would:
- Eliminate roughly 60 unnecessary listener add/remove cycles per second while scrolling.
- Reduce unnecessary re-renders caused by the throttle flag.
- Keep only the scroll-position update responsible for UI re-renders.
- Prevent the same performance issue from being propagated if the reusable hook is adopted elsewhere.
- Potentially improve scrolling responsiveness, particularly on mobile and lower-end devices.
There should be no visible behavioral change to the animation.
Screenshots
N/A. There is no visible UI change.
The behavior can be verified using React DevTools by observing render counts, or by instrumenting the scroll listener to confirm that it is no longer repeatedly added and removed during scrolling.
Environment
- Host OS: code-level issue
- Browser: All
- 主要言語
- JavaScript
- スター
- 1.1k
- フォーク
- 1.6k
- 平均マージ
- 3日 23時間
- マージ済み PR(30日)
- 34
環境構築
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
layer5io/layer5 のほかの issue
-
Unwanted white border around "Join the Conversation" (Discuss) card on Learn, Community & FAQ pagesオープンframework/gatsby help wanted kind/bug
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
layer5io/layer5#8158 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
framework/gatsby help wanted kind/bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
layer5io/layer5#8155 · コメント 3 件 ·
メンテナーはふだん 2 日以内に返信
-
framework/gatsby help wanted kind/bug
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
layer5io/layer5#8147 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 2 日以内に返信
-
[UI]: MeshMate logo disappears to the left on the MeshMates page対応中かも @ayanasarkar が 5 日前に担当しました。 オープンframework/gatsby help wanted kind/bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
layer5io/layer5#8123 · コメント 3 件 · 担当者 1 名 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
layer5io/layer5#8075 · コメント 2 件 ·
メンテナーはふだん 2 日以内に返信
layer5io/layer5 の issue をすべて見る
似ている issue
-
automation models
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
needs:triage
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 1 日以内に返信
-
enhancement status: needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
mastra-ai/mastra#25508 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 1 日以内に返信
-
agentic-workflows
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
githubnext/gh-aw-cao#15017 ·
メンテナーはふだん 1 日以内に返信