virtual-list
यह क्या करती है
यह स्किल वर्चुअल स्क्रॉलिंग समझाती है, जिसमें केवल दिखने वाले क्षेत्र के पास के आइटम पेज पर बनते हैं। यह निश्चित और बदलती पंक्ति ऊंचाई दोनों वाली सूचियों को कवर करती है। यह वेब पेज पर बहुत लंबी सूचियां दिखाने वाले डेवलपर्स के लिए है।
कब इस्तेमाल करें
- ✓जब किसी वेब सूची में हज़ारों आइटम हों और पेज धीमा होने लगे।
- ✓जब आइटम की ऊंचाई निश्चित हो और आप सरल, तेज़ सूची चाहते हैं।
- ✓जब आइटम की ऊंचाई अलग-अलग हो और फिर भी सूची तेज़ रहनी चाहिए।
Skill का लिंक
https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/virtual-list/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“क्या आप मेरे वेब पेज पर दस हज़ार आइटम की ऐसी सूची बना सकते हैं जो सहजता से स्क्रॉल हो?”
हर हफ़्ते 5 नई skills, 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
अक्सर पूछे जाने वाले सवाल
वर्चुअल स्क्रॉलिंग क्या है?
यह एक तरीका है जिसमें केवल वे आइटम बनाए जाते हैं जो दिखाई दे रहे हों, सारे आइटम पेज पर बनाने के बजाय।
दोनों सूची प्रकारों में क्या अंतर है?
एक समान ऊंचाई वाले आइटम के लिए है, और दूसरा बदलती ऊंचाई वाले आइटम के लिए, जो टुकड़ों में बनते हैं।
क्या स्क्रॉलिंग सहज रहती है?
स्किल स्क्रॉल पर एक समय-आधारित अपडेट इस्तेमाल करती है, ताकि हर छोटी हरकत पर पेज अतिरिक्त काम न करे।
जानकारी
लेखक का मूल विवरण
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
- अपडेट की गई
- 1/11/2026
कमेंट
- …
इस repository की और skills
agentpilot
7.8kआपके एजेंट को AgentPilot से प्रोजेक्ट को चरण-दर-चरण सुधारने में मदद करती है, जिसमें बदलाव सुझाए, परखे और स्कोर किए जाते हैं।
openspace
7.8kआपके एजेंट को OpenSpace सेट करने में मदद करती है, जो एजेंट स्किल्स सहेजता और वापस लाता है, और MCP के ज़रिए आपके AI ऐप से जुड़ता है।
rsi-arena
7.8kआपके एजेंट को AIME और Terminal-Bench जैसे मानक AI बेंचमार्क टेस्ट सेट करने और चलाने में मदद करती है, ताकि सुधार के तरीकों की तुलना हो सके।
experiment-guide
7.8kआपके एजेंट को छोटे प्रयोग बनाने, उनके नतीजे पढ़ने और जाँच के दौरान उपयोगी निष्कर्ष लिखने में मदद करती है।
मिलती-जुलती skills
angular-developer
280kआपके एजेंट को Angular code बनाने और प्रोजेक्ट स्ट्रक्चर पर सलाह देने में मदद करता है। नए प्रोजेक्ट शुरू करने, code के हिस्से बनाने, या performance और accessibility सुधारने में उपयोगी है।
frontend-a11y
280kआपके एजेंट को web interfaces को सबके लिए accessible बनाने में मदद करता है। यह सुनिश्चित करता है कि websites और apps screen readers और keyboard navigation के साथ अच्छे से काम करें।
frontend-patterns
280kआपके एजेंट को React और Next.js में frontend development के modern patterns लागू करने में मदद करता है। यह performance optimize करता है, state manage करता है और best practices फॉलो करवाता है।