본문으로 건너뛰기
Skillpedia
웹사이트 및 UI (프런트엔드)7.8k · #13091

virtual-list

하는 일

이 스킬은 화면에 보이는 항목 근처만 그리는 가상 스크롤을 설명합니다. 높이가 고정된 목록과 높이가 다른 목록을 다룹니다. 웹 페이지에 아주 긴 목록을 보여 주는 개발자를 위한 스킬입니다.

사용하는 경우

  • ✓웹 목록에 항목이 수천 개 있고 페이지가 느려질 때.
  • ✓항목 높이가 고정되어 있고 간단하면서 빠른 목록을 원할 때.
  • ✓항목 높이가 달라도 여전히 빠른 목록이 필요할 때.

스킬 링크

https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/virtual-list/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/virtual-list/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“웹 페이지에 있는 만 개의 항목을 부드럽게 스크롤되는 목록으로 만들어 주실 수 있나요?”

매주 새 스킬 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 (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
업데이트
2026. 11. 1.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬