Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

feat(cdk/scrolling): Integrate Pretext Library for Precise Text Measurement in Auto-Size Virtual Scroll

Offen
#33,011 1 Kommentar 5 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Anfängerfreundlichkeit
35/100
Issue-Typ
Feature
Klarheit
Muss geklärt werden
Aktivitätsstatus
Ruhig
Tech-Stack
angular, typescript

Rechercherichtung

Beginne mit der AutoSizeVirtualScrollStrategy und ihrem ItemSizeAverager. Überprüfe anschließend die vorgeschlagenen Pretext-APIs prepare() und layout() sowie, wie sich textlastige Elemente von komplexen Layouts unterscheiden. Lege den Integrationsumfang, das Fallback-Verhalten und die erforderliche Validierung fest, um eine genaue Größenbestimmung ohne Regressionen nachzuweisen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

area: cdk/scrolling feature P4
Feature Description

Description:

Problem Statement

The current AutoSizeVirtualScrollStrategy implementation relies on ItemSizeAverager to estimate the size of unseen items based on historical measurements. While this approach works for many scenarios, it has several limitations:

  1. Reflow overhead: Must render elements first before measuring, triggering expensive layout reflows
  2. Inaccurate predictions: Averaging-based estimation can be imprecise for heterogeneous content, especially variable-height text items
  3. Performance bottlenecks: Frequent DOM measurements during scrolling impact performance
  4. Layout shifts: Predictive scrolling may cause visual jumps when estimated sizes differ significantly from actual sizes
Proposed Solution

I'd like to propose integrating the Pretext library (https://github.com/chenglou/pretext) into the auto-size virtual scroll strategy. Pretext is a pure JavaScript/TypeScript library that provides:

  • Accurate text measurement without DOM: Calculates text dimensions using pure arithmetic, avoiding getBoundingClientRect and offsetHeight
  • Excellent performance: Benchmarks show layout() operations at ~0.09ms for 500 texts (hot path)
  • Comprehensive language support: Handles all languages, emojis, and mixed-bidi text correctly
  • Predictive sizing: Enables pre-rendering size calculations for virtual lists
Implementation Ideas

The integration could work as follows:

  1. For text-heavy virtual lists:

    • When items contain primarily text content with known font/line-height configurations
    • Use Pretext's prepare() + layout() API to calculate heights before rendering
    • This allows the scroll strategy to know exact item sizes upfront
  2. Hybrid approach:

    • Use Pretext for text content measurement
    • Fall back to current DOM measurement for non-text or complex layouts
    • Combine both for maximum accuracy
  3. Performance optimization:

    • Cache PreparedText objects for reuse during resize events
    • Only re-run layout() (the cheap 0.09ms operation) when container width changes
Benefits
  • Eliminates layout reflow for text measurement in virtual lists
  • More accurate scrolling behavior with predictable item sizes
  • Better performance especially for long lists with variable-height text items
  • Reduced visual jumps during scrolling since sizes are pre-calculated
  • Support for all languages and scripts including complex layouts
Example Use Case
  • Chat applications with varying message lengths.
  • Feeds/Dashboards with dynamic text content.
Use Case

No response

Vorherrschende Sprache
TypeScript
Sterne
25k
Forks
6.8k
Ø Merge
1 T. 1 Std.
Gemergte PRs (30 T.)
84

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus angular/components

Alle Issues in angular/components

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.