मुख्य सामग्री पर जाएँ
Skillpedia
वेबसाइट और UI (frontend)7.8k · #13091

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 पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/virtual-list/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

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 (overscan parameter) 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 onRecycle callback
  • 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

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

मिलती-जुलती skills