virtual-list
できること
このスキルは、見えている領域の近くの項目だけをページに描く、仮想スクロールを説明します。高さが固定されたリストと、高さが変わるリストの両方を扱います。Webページで非常に長いリストを表示する開発者向けです。
使う場面
- ✓Webのリストに数千の項目があり、ページが遅くなるとき。
- ✓項目の高さが固定で、シンプルで速いリストがほしいとき。
- ✓項目の高さが違っていても、速さを保つリストが必要なとき。
スキルのリンク
https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/virtual-list/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“Webページに1万項目のリストを作り、なめらかにスクロールできるようにしてもらえますか?”
毎週5つの新しいスキル。1分で読めます。
仕組み
リストは、再利用できるページの要素を少数だけ保持し、見えている行だけを描きます。また、ちらつきを防ぐため、上下に少し余分な行も描きます。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Virtual List Implementation Skill
Overview
This skill teaches you how to implement a high-performance virtual scrolling list component that can efficiently render thousands or millions of items by only creating DOM nodes for visible items plus a small buffer.
Analysis of Reference Implementation
The VirtualList component from /worldmonitor/src/components/VirtualList.ts demonstrates professional-grade virtual scrolling with the following patterns:
1. Chunk-Based Rendering Pattern
The implementation uses two complementary strategies:
VirtualList (Fixed-Height Items)
- Item Pool Management: Maintains a pool of reusable DOM elements (
PooledElement[]) - Viewport Calculation: Calculates visible range based on
scrollTop,itemHeight, and viewport dimensions - Overscan Buffer: Renders extra items above/below viewport (
overscanparameter) to prevent flickering during scroll
WindowedList (Variable-Height Items)
- Chunk-Based Approach: Divides items into chunks (default 10 items per chunk)
- Lazy Chunk Rendering: Only renders chunks that are visible or within buffer range
- Placeholder Elements: Creates placeholders for all chunks upfront, renders content on-demand
2. Scroll Listener Optimization
private handleScroll = (): void => {
if (this.scrollRAF !== null) return;
this.scrollRAF = requestAnimationFrame(() => {
this.scrollRAF = null;
if (!this.isDestroyed) {
this.updateVisibleRange();
}
});
};
Key Optimizations:
- RequestAnimationFrame Throttling: Prevents multiple renders in same frame
- Passive Listeners:
{ passive: true }improves scroll performance - Debounce Check: Guards against duplicate RAF calls
- Cleanup Check: Prevents rendering after destruction
3. DOM Recycling Strategy
The implementation uses a sophisticated two-pass recycling algorithm:
Pass 1: Identify Reusable Elements
for (const pooled of this.itemPool) {
if (pooled.currentIndex >= visibleStart && pooled.currentIndex < visibleEnd) {
usedIndices.add(pooled.currentIndex);
}
}
Pass 2: Recycle and Reassign
while (poolIndex < this.itemPool.length) {
const pooled = this.itemPool[poolIndex]!;
if (pooled.currentIndex < visibleStart || pooled.currentIndex >= visibleEnd) {
// Recycle this element
if (this.onRecycle) {
this.onRecycle(pooled.element);
}
pooled.currentIndex = i;
this.renderItem(i, pooled.element);
pooled.element.style.transform = `translateY(${i * this.itemHeight}px)`;
poolIndex++;
break;
}
poolIndex++;
}
Benefits:
- Minimizes DOM manipulation
- Reuses existing elements when possible
- Allows cleanup of event listeners via
onRecyclecallback - Uses
transform: translateY()for GPU-accelerated positioning
4. Performance Optimizations
Spacer Elements for Virtual Height
this.topSpacer.style.height = `${visibleStart * this.itemHeight}px`;
this.bottomSpacer.style.height = `${Math.max(0, (this.totalItems - visibleEnd) * this.itemHeight)}px`;
- Creates illusion of full list height without rendering all items
- Maintains accurate scrollbar size and position
Skip Unnecessary Updates
if (visibleStart === this.visibleStart && visibleEnd === this.visibleEnd) {
return;
}
CSS Positioning Strategy
element.style.position = 'absolute';
element.style.top = '0';
element.style.left = '0';
element.style.right = '0';
element.style.transform = 'translateY(-9999px)'; // Hide off-screen
- Absolute positioning for precise control
- Transform for GPU acceleration
- Off-screen positioning instead of display:none (preserves element state)
ResizeObserver Integration
if (typeof ResizeObserver !== 'undefined') {
this.resizeObserver = new ResizeObserver(() => {
if (!this.isDestroyed) {
this.updateVisibleRange();
}
});
this.resizeObserver.observe(this.viewport);
}
- Automatically recalculates visible range when viewport resizes
- Progressive enhancement (checks for browser support)
Complete TypeScript Implementation Template
Below is a simplified but fully functional virtual list implementation that you can drop into any vanilla TypeScript project:
/**
* SimpleVirtualList - A simplified virtual scrolling implementation
*
* Usage:
* ```typescript
* const virtualList = new Sim
よくある質問
仮想スクロールとは何ですか?
すべての項目をページに作る代わりに、見えている項目だけを描く方法です。
2種類のリストの違いは何ですか?
1つは同じ高さの項目用で、もう1つは高さが変わる項目用です。後者はかたまりごとに描きます。
スクロールはなめらかなままですか?
スキルは、スクロールのたびに余分な処理をしないよう、一定時間ごとの更新を使います。
詳細
作者による元の説明
Implement efficient virtual scrolling for rendering large lists with DOM recycling, chunk-based rendering, and performance optimizations
repo: HKUDS/AgentPilot
人気
- GitHubのスター
- 7.8k
- ランキング
- #13091
- ライセンス
- MIT
- 更新日
- 2026/11/1
コメント
- …
このリポジトリの他のスキル
agentpilot
7.8kエージェントが、作業を準備し、変更案を提案してテストし、評価するAgentPilotのループを実行することで、プロジェクトを段階的に改善できるよう支援します。
openspace
7.8kエージェントが、スキルを保存し取り出すツールであるOpenSpaceをセットアップし、MCPを通じてAIアプリに接続できるよう支援します。
rsi-arena
7.8kエージェントが、AIMEやTerminal-Benchなどの標準的なAIベンチマークテストをセットアップして実行し、異なる改善方法を比較できるよう支援します。
experiment-guide
7.8kエージェントが、プログラムを改善する方法を調べる間に、小さな実験を計画し、その結果を読み、発見を記録できるよう支援します。
似ているスキル
angular-developer
280kエージェントがAngularのコードを作成し、プロジェクト構成についてアドバイスできるようにします。新しいプロジェクトの開始、コード部品の作成、パフォーマンスやアクセシビリティの改善に役立ちます。
frontend-a11y
280kエージェントが Web インターフェースを誰にとっても使いやすくするよう支援します。スクリーンリーダーやキーボード操作に対応し、サイトやアプリが適切に動作するようにします。
frontend-patterns
280kエージェントがフロントエンド開発の最新パターンを適用できるようにします。React と Next.js において、パフォーマンスの最適化、状態管理、ベストプラクティスの遵守を行います。