<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="fr">
  
  <title>Pokipedia Tech</title>
  <subtitle>Les problèmes rencontrés en construisant Pokipedia, les choix faits pour les résoudre et leur mise en œuvre, mesures et code à l’appui.</subtitle>
  <link href="https://tech.pokipedia.com/feed.xml" rel="self" />
  <link href="https://tech.pokipedia.com/" />
  <updated>2026-11-24T00:00:00Z</updated>
  <id>https://tech.pokipedia.com/</id>
  <author>
    <name>Pokipedia</name>
  </author>
  <entry>
    <title>Des galeries de centaines de cartes à 60 images par seconde</title>
    <link href="https://tech.pokipedia.com/galeries-de-cartes-virtualisees/" />
    <updated>2026-11-24T00:00:00Z</updated>
    <id>https://tech.pokipedia.com/galeries-de-cartes-virtualisees/</id>
    <content type="html">&lt;h2&gt;Le contexte : des cartes qui ne sont pas des vignettes&lt;/h2&gt;
&lt;p&gt;Dans Pokipedia, on ouvre des boosters, on collectionne, on fusionne et on échange des cartes. La page « Mes cartes »
affiche toute la collection d&#39;un joueur dans une grille, une vignette par exemplaire. Et un exemplaire peut être en
plusieurs versions (normale, shiny, full art), avoir un rang de fusion, un numéro de série, être en vente…&lt;/p&gt;
&lt;p&gt;Chaque vignette n&#39;est donc pas une simple image :&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;un composant &lt;code&gt;HoloCard&lt;/code&gt; qui incline la carte en 3D au survol (&lt;code&gt;transform-style: preserve-3d&lt;/code&gt;), avec reflets et
foil holographique pour les shiny ;&lt;/li&gt;
&lt;li&gt;un cadre aux couleurs de la rareté, une illustration, un texte, un score dans une pastille, une signature ;&lt;/li&gt;
&lt;li&gt;des pastilles à cheval sur le bord (« Nouveau », « En vente », « En booster »…), qui suivent l&#39;inclinaison ;&lt;/li&gt;
&lt;li&gt;pour certaines raretés, des animations en boucle (reflet doré qui balaie les cartes shiny).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Au total, &lt;strong&gt;environ 45 éléments HTML par carte&lt;/strong&gt;. Un joueur actif a vite plusieurs centaines d&#39;exemplaires : notre
compte de test en a 687.&lt;/p&gt;
&lt;p&gt;La page utilisait un défilement infini côté client : toutes les données étaient chargées d&#39;un coup (filtres, tris et
compteurs portent sur l&#39;ensemble), mais l&#39;affichage commençait à 48 cartes et en ajoutait 48 chaque fois que le bas
de la liste approchait. Sans jamais en retirer.&lt;/p&gt;
&lt;h2&gt;Mesurer avant de corriger&lt;/h2&gt;
&lt;p&gt;« Ça rame un peu » ne suffit pas pour choisir une solution. Nous avons écrit un petit protocole de mesure, exécuté
directement dans la page :&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;build de production&lt;/strong&gt; (le mode développement de React fausse tout) servi par &lt;code&gt;vite preview&lt;/code&gt;, sur la base de dev ;&lt;/li&gt;
&lt;li&gt;sur chaque page : 2 secondes au repos, puis 4 secondes de &lt;strong&gt;défilement régulier à 1 200 px/s&lt;/strong&gt;, piloté par
&lt;code&gt;requestAnimationFrame&lt;/code&gt; ;&lt;/li&gt;
&lt;li&gt;relevé du temps de chaque image : images par seconde, 95e centile, part des images de plus de 25 ms (des
saccades visibles sur un écran à 60 Hz), et tâches longues (&amp;gt; 50 ms) via &lt;code&gt;PerformanceObserver&lt;/code&gt; ;&lt;/li&gt;
&lt;li&gt;un MacBook M1, écran à 60 Hz. Chaque mesure décisive est répétée, la machine n&#39;étant pas au repos.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// Défilement régulier et relevé du temps de chaque image.&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; frames &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; last &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; performance&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;now&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; start &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; last&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;step&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;now&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  frames&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;now &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; last&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  last &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; now&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;scrollingElement&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;scrollTop &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;now &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; start&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;SPEED&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;now &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; start &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;DURATION&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;requestAnimationFrame&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;step&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token function&quot;&gt;requestAnimationFrame&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;step&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Premier passage sur une vingtaine de pages de liste et sur l&#39;atelier de fusion :&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Page&lt;/th&gt;
&lt;th&gt;Défilement&lt;/th&gt;
&lt;th&gt;Remarque&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Mes cartes (144 cartes affichées)&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;32-33 img/s&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;gels jusqu&#39;à 229 ms, 44-52 img/s même au repos&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Mes cartes, liste complète (687 cartes)&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;11-25 img/s&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;quasi inutilisable&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Fusion&lt;/td&gt;
&lt;td&gt;35-47 img/s&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Marché&lt;/td&gt;
&lt;td&gt;40-51 img/s&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Liste des albums&lt;/td&gt;
&lt;td&gt;42-50 img/s&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Collections, classement, profils, classeurs…&lt;/td&gt;
&lt;td&gt;56-60 img/s&lt;/td&gt;
&lt;td&gt;rien à signaler&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2&gt;Trouver les coupables, un par un&lt;/h2&gt;
&lt;p&gt;Plutôt que de deviner, nous avons désactivé les effets un à un en injectant une feuille de style dans la page, puis
remesuré. C&#39;est rapide, réversible, et ça sépare les causes.&lt;/p&gt;
&lt;h3&gt;Coupable n° 1 : le flou d&#39;arrière-plan, multiplié par cent&lt;/h3&gt;
&lt;p&gt;La pastille de score de chaque carte avait un &lt;code&gt;backdrop-filter: blur(4px)&lt;/code&gt;. Joli sur une carte. Mais un flou
d&#39;arrière-plan oblige le navigateur à recalculer ce qu&#39;il y a derrière l&#39;élément &lt;strong&gt;à chaque image&lt;/strong&gt;, pour chaque carte
visible, pendant tout le défilement.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Mesure (150 cartes)&lt;/th&gt;
&lt;th&gt;Avec le flou&lt;/th&gt;
&lt;th&gt;Sans le flou&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Essai 1&lt;/td&gt;
&lt;td&gt;39 img/s&lt;/td&gt;
&lt;td&gt;52 img/s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Essai 2&lt;/td&gt;
&lt;td&gt;39 img/s&lt;/td&gt;
&lt;td&gt;50 img/s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Essai 3&lt;/td&gt;
&lt;td&gt;37 img/s&lt;/td&gt;
&lt;td&gt;51 img/s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Même chose sur la Fusion (36 → 59 img/s), le Marché (40 → 58) et la liste des albums, où c&#39;étaient les 31 pastilles
de compteurs qui étaient floutées (42 → 60).&lt;/p&gt;
&lt;p&gt;Le comble : le fond de la pastille était déjà opaque à 62 %. Le flou ne se voyait presque pas. Nous l&#39;avons remplacé
par un fond un peu plus opaque, visuellement identique :&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.card-score&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;/* Fond plus opaque plutôt qu&#39;un flou d&#39;arrière-plan : recalculé à chaque image pour chaque carte. */&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rgba&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;20&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 10&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 30&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0.78&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;/* au lieu de 0.62 + backdrop-filter: blur(4px) */&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Quatre lignes de CSS, livrées en &lt;strong&gt;version 1.21.1&lt;/strong&gt; : la Fusion, le Marché et les albums repassent à 56-58 img/s.&lt;/p&gt;
&lt;h3&gt;Les fausses pistes&lt;/h3&gt;
&lt;p&gt;Tout ce qui « devrait » coûter cher ne coûtait pas cher. Désactivés un par un, sans gain mesurable :&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;l&#39;&lt;strong&gt;ombre floue&lt;/strong&gt; sous chaque carte (&lt;code&gt;filter: blur(26px)&lt;/code&gt;) : elle n&#39;est affichée qu&#39;au survol ;&lt;/li&gt;
&lt;li&gt;les &lt;strong&gt;animations en boucle&lt;/strong&gt; (reflets dorés, ciel étoilé du menu) : quelques images par seconde au mieux ;&lt;/li&gt;
&lt;li&gt;le flou de l&#39;&lt;strong&gt;en-tête collant&lt;/strong&gt; ;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;mettre les cartes à plat&lt;/strong&gt; tant qu&#39;elles ne sont pas survolées (sans 3D) : c&#39;était même pire.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Coupable n° 2 : le nombre de cartes dans la page&lt;/h3&gt;
&lt;p&gt;Restait Mes cartes. En gardant le flou retiré et en ne laissant que les N premières cartes dans la page :&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Cartes dans la page&lt;/th&gt;
&lt;th&gt;Défilement&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;50&lt;/td&gt;
&lt;td&gt;54 img/s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;150&lt;/td&gt;
&lt;td&gt;37-51 img/s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;687&lt;/td&gt;
&lt;td&gt;22-25 img/s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;La vitesse dépend du nombre de cartes &lt;strong&gt;présentes&lt;/strong&gt;, y compris celles qui sont loin hors de l&#39;écran. Avec 687 cartes,
la page compte plus de 30 000 éléments, dont des milliers de couches 3D que le navigateur doit tenir à jour.&lt;/p&gt;
&lt;p&gt;Nous avons essayé &lt;code&gt;content-visibility: auto&lt;/code&gt;, censé sauter le rendu des éléments hors de l&#39;écran : aucun gain. Il
évite de peindre les cartes lointaines, mais elles restent dans le document, avec leurs couches de composition.&lt;/p&gt;
&lt;h2&gt;Les solutions possibles&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Solution&lt;/th&gt;
&lt;th&gt;Pour&lt;/th&gt;
&lt;th&gt;Contre&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Pagination&lt;/strong&gt; (« page 1, 2, 3 », au plus ~150 cartes)&lt;/td&gt;
&lt;td&gt;simple, robuste&lt;/td&gt;
&lt;td&gt;navigation hachée ; une collection se parcourt, elle ne se feuillette pas&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Défilement infini qui retire les cartes du haut&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;pas de dépendance&lt;/td&gt;
&lt;td&gt;c&#39;est une virtualisation qui ne dit pas son nom, sans ses outils&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Cartes plus légères dans les grilles&lt;/strong&gt; (sans 3D, sans effets)&lt;/td&gt;
&lt;td&gt;gain par carte&lt;/td&gt;
&lt;td&gt;appauvrit l&#39;expérience, et ne règle pas le fond : le coût reste proportionnel au nombre de cartes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Virtualisation&lt;/strong&gt; : ne rendre que ce qui est à l&#39;écran&lt;/td&gt;
&lt;td&gt;coût constant, quelle que soit la taille de la collection&lt;/td&gt;
&lt;td&gt;plus de complexité : mesure, sélection, clavier, tests&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Le point décisif : &lt;strong&gt;avec la virtualisation, les performances ne dépendent plus de la taille de la collection&lt;/strong&gt;. Que
le joueur ait 50 ou 5 000 cartes, il y en a toujours une trentaine dans la page. C&#39;est la seule solution qui règle le
problème au lieu de le repousser.&lt;/p&gt;
&lt;h2&gt;La solution retenue : une grille virtualisée par lignes&lt;/h2&gt;
&lt;p&gt;Nous avons choisi &lt;a href=&quot;https://tanstack.com/virtual&quot;&gt;&lt;code&gt;@tanstack/react-virtual&lt;/code&gt;&lt;/a&gt; : petit, sans style imposé, capable de
suivre le défilement de la fenêtre (et non d&#39;un conteneur à barre de défilement) et de mesurer lui-même les éléments.&lt;/p&gt;
&lt;h3&gt;L&#39;idée&lt;/h3&gt;
&lt;p&gt;La page garde la hauteur de toute la grille : la barre de défilement se comporte comme si toutes les cartes étaient
là. Mais seules les lignes visibles, plus trois au-dessus et trois au-dessous, sont réellement rendues. En défilant,
les lignes qui sortent sont retirées et celles qui entrent sont créées.&lt;/p&gt;
&lt;p&gt;Les données, elles, ne changent pas : la liste complète était déjà en mémoire. Filtres, tri et compteurs continuent de
porter sur l&#39;ensemble ; seul le rendu change.&lt;/p&gt;
&lt;h3&gt;Découper une grille responsive en lignes&lt;/h3&gt;
&lt;p&gt;La grille CSS existante place autant de cartes par ligne que la largeur le permet
(&lt;code&gt;repeat(auto-fill, minmax(…, 1fr))&lt;/code&gt;), et deux sur mobile. Plutôt que de recalculer ces règles en JavaScript, nous
laissons CSS décider et nous lisons le résultat :&lt;/p&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// Chaque ligne rendue est elle-même une grille .card-grid : avec auto-fill, son nombre de colonnes&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;// ne dépend que de sa largeur, pas du nombre de cartes qu&#39;elle contient.&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; row &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; container&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;:scope &gt; [data-index]&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; tracks &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;getComputedStyle&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;row&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;gridTemplateColumns&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;split&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39; &#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;length&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;tracks &lt;span class=&quot;token operator&quot;&gt;!==&lt;/span&gt; cols&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;setCols&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;tracks&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;La liste est ensuite découpée en lignes de &lt;code&gt;cols&lt;/code&gt; cartes, et c&#39;est ce tableau de lignes qui est virtualisé :&lt;/p&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; rows &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;useMemo&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;chunk&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;items&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; cols&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;items&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; cols&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; virtualizer &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;useWindowVirtualizer&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; rows&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;length&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token function-variable function&quot;&gt;estimateSize&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;420&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;            &lt;span class=&quot;token comment&quot;&gt;// estimation, corrigée dès que la ligne est mesurée&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;overscan&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;                        &lt;span class=&quot;token comment&quot;&gt;// trois lignes d&#39;avance au-dessus et au-dessous&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;scrollMargin&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; gridTopInPage&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;        &lt;span class=&quot;token comment&quot;&gt;// la grille ne commence pas en haut de la page&lt;/span&gt;
  &lt;span class=&quot;token function-variable function&quot;&gt;getItemKey&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; rows&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;pull_id&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Un &lt;code&gt;ResizeObserver&lt;/code&gt; sur la grille et sur la page met à jour le nombre de colonnes et la position de la grille quand la
fenêtre change de taille ou que la barre d&#39;outils au-dessus passe sur deux lignes.&lt;/p&gt;
&lt;h3&gt;Mesurer plutôt qu&#39;estimer&lt;/h3&gt;
&lt;p&gt;Une ligne n&#39;a pas toujours la même hauteur : une carte avec une pastille, une police qui charge… Chaque ligne rendue
est mesurée (&lt;code&gt;ref={virtualizer.measureElement}&lt;/code&gt;), et la hauteur totale se corrige d&#39;elle-même : estimée à
138 × 420 px au départ, elle tombe à 138 × 325 px une fois les lignes mesurées. Sans cette mesure, la barre de
défilement sauterait.&lt;/p&gt;
&lt;h3&gt;&lt;code&gt;top&lt;/code&gt; plutôt que &lt;code&gt;transform&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;La documentation place habituellement les éléments virtualisés avec &lt;code&gt;transform: translateY(…)&lt;/code&gt;. Mais un &lt;code&gt;transform&lt;/code&gt;
crée un &lt;strong&gt;contexte d&#39;empilement&lt;/strong&gt; : une carte survolée, qui grandit et s&#39;incline, passerait alors sous la ligne
suivante. Nous plaçons donc les lignes avec &lt;code&gt;top&lt;/code&gt;, qui n&#39;en crée pas :&lt;/p&gt;
&lt;pre class=&quot;language-jsx&quot;&gt;&lt;code class=&quot;language-jsx&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;className&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;card-grid-virtual&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;style&lt;/span&gt;&lt;span class=&quot;token script language-javascript&quot;&gt;&lt;span class=&quot;token script-punctuation punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token literal-property property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; virtualizer&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getTotalSize&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;virtualizer&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getVirtualItems&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt;
      &lt;span class=&quot;token attr-name&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;token script language-javascript&quot;&gt;&lt;span class=&quot;token script-punctuation punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;v&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;key&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;data-index&lt;/span&gt;&lt;span class=&quot;token script language-javascript&quot;&gt;&lt;span class=&quot;token script-punctuation punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;v&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;index&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;ref&lt;/span&gt;&lt;span class=&quot;token script language-javascript&quot;&gt;&lt;span class=&quot;token script-punctuation punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;virtualizer&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;measureElement&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token attr-name&quot;&gt;className&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;card-grid card-grid-row&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;style&lt;/span&gt;&lt;span class=&quot;token script language-javascript&quot;&gt;&lt;span class=&quot;token script-punctuation punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token literal-property property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; v&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;start &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; scrollMargin &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;rows&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;v&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;index&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;renderItem&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;L&#39;écart entre deux lignes devient une marge basse de chaque ligne, pour rester mesurée avec elle. Les pastilles à
cheval sur le bord des cartes débordent librement : rien n&#39;est rogné.&lt;/p&gt;
&lt;h3&gt;La sélection au lasso, sans les cartes&lt;/h3&gt;
&lt;p&gt;Mes cartes permet de sélectionner plusieurs cartes en traçant un rectangle à la souris, la page défilant d&#39;elle-même
près des bords. Le lasso cherchait les cartes touchées… parmi les éléments de la page. Or, avec la virtualisation, une
carte sortie de l&#39;écran n&#39;est plus dans la page : un lasso étendu en défilant perdait les cartes du haut.&lt;/p&gt;
&lt;p&gt;La grille expose désormais un &lt;code&gt;hitTest(rect)&lt;/code&gt; qui calcule les cartes touchées par géométrie, à partir des positions
des lignes (connues de la bibliothèque, même pour les lignes non rendues) et de la largeur des colonnes :&lt;/p&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token function&quot;&gt;hitTest&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; left&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; top&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; right&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; bottom &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; ids &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; m &lt;span class=&quot;token keyword&quot;&gt;of&lt;/span&gt; virtualizer&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;measurementsCache&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;      &lt;span class=&quot;token comment&quot;&gt;// toutes les lignes, rendues ou non&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; y1 &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; m&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;start &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; window&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;scrollY&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; y2 &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; m&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;end &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; window&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;scrollY &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; rowGap&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;y2 &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; top &lt;span class=&quot;token operator&quot;&gt;||&lt;/span&gt; y1 &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; bottom&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;continue&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    rows&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;m&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;index&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;forEach&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;item&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; c&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; x1 &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; gridLeft &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; c &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;colWidth &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; gap&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;x1 &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; colWidth &lt;span class=&quot;token operator&quot;&gt;&gt;=&lt;/span&gt; left &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; x1 &lt;span class=&quot;token operator&quot;&gt;&amp;lt;=&lt;/span&gt; right&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; ids&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;item&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;pull_id&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; ids&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Le lasso utilise ce calcul quand il est fourni, et retombe sur la recherche dans la page sinon (autres grilles).
Résultat vérifié : un lasso étendu en défilant sélectionne 54 cartes alors que 15 seulement sont rendues.&lt;/p&gt;
&lt;h3&gt;Ce qui marche sans rien faire&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;« Tout sélectionner »&lt;/strong&gt; : la sélection est un état React (un ensemble d&#39;identifiants), pas une classe sur des
éléments. Elle couvre donc toute la collection.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Le clavier&lt;/strong&gt; : une carte qui reçoit le focus avec Tab est amenée à l&#39;écran par le navigateur, ce qui fait rendre
les lignes suivantes. On parcourt la collection carte par carte, la page suit.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Le badge « Nouveau »&lt;/strong&gt;, retiré quand la carte a été vue à l&#39;écran : il repose sur un &lt;code&gt;IntersectionObserver&lt;/code&gt; posé
par une &lt;code&gt;ref&lt;/code&gt;, qui fonctionne aussi bien avec des cartes créées et retirées au fil du défilement.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Les tests de bout en bout&lt;/h3&gt;
&lt;p&gt;Un test comptait les pastilles « En booster » sur toute la page : il en trouvait 3 sur 5, les deux autres n&#39;étant pas
rendues. Chaque carte porte maintenant son identifiant d&#39;exemplaire (&lt;code&gt;data-pull&lt;/code&gt;), et le test parcourt la grille en
défilant pour relever les exemplaires concernés. Un nouveau test vérifie le comportement avec 200 exemplaires : moins
de 100 cartes rendues, la dernière atteinte en défilant, et « Tout » qui sélectionne bien les 200.&lt;/p&gt;
&lt;h2&gt;Les gains&lt;/h2&gt;
&lt;p&gt;Mesures en build de production, même protocole qu&#39;au départ :&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Cas&lt;/th&gt;
&lt;th&gt;Avant&lt;/th&gt;
&lt;th&gt;Après le flou (1.21.1)&lt;/th&gt;
&lt;th&gt;Après la virtualisation (1.22.0)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Mes cartes, 687 cartes, défilement normal&lt;/td&gt;
&lt;td&gt;11-25 img/s&lt;/td&gt;
&lt;td&gt;22-25 img/s&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;57-59 img/s&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Mes cartes, 687 cartes, défilement rapide (3 000 px/s)&lt;/td&gt;
&lt;td&gt;–&lt;/td&gt;
&lt;td&gt;–&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;54-56 img/s&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Mes cartes, format téléphone (375 px)&lt;/td&gt;
&lt;td&gt;–&lt;/td&gt;
&lt;td&gt;–&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;60 img/s&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Fusion&lt;/td&gt;
&lt;td&gt;35-38 img/s&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;56-58 img/s&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;–&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Marché&lt;/td&gt;
&lt;td&gt;40-51 img/s&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;56-58 img/s&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;–&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Liste des albums&lt;/td&gt;
&lt;td&gt;42-50 img/s&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;56-60 img/s&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;–&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Éléments dans la page (Mes cartes, 687 cartes)&lt;/td&gt;
&lt;td&gt;~30 000&lt;/td&gt;
&lt;td&gt;~30 000&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;~2 000&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Deux corrections complémentaires : retirer le flou a réglé les pages de taille raisonnable ; la virtualisation a
rendu Mes cartes indépendante de la taille de la collection.&lt;/p&gt;
&lt;h2&gt;Les limites, honnêtement&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;La recherche du navigateur&lt;/strong&gt; (Ctrl+F) ne trouve que les cartes à l&#39;écran. Le champ de recherche de la page, lui,
porte sur toute la collection.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Le format téléphone&lt;/strong&gt; a été mesuré en émulation, sans ralentir le processeur : un vrai téléphone sera plus lent. Le
gain devrait rester du même ordre, puisque le nombre de cartes dans la page ne dépend plus de la collection.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;La Fusion et le Marché&lt;/strong&gt; ne sont pas encore virtualisés. Ils sont fluides aujourd&#39;hui, mais deviendront les
prochains candidats quand les listes grandiront ; le composant &lt;code&gt;VirtualCardGrid&lt;/code&gt; est prêt pour eux.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;À retenir&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Mesurer d&#39;abord&lt;/strong&gt;, sur un build de production, avec un protocole répétable. Notre intuition désignait l&#39;ombre
floue et les animations ; elles ne coûtaient presque rien.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Isoler les causes&lt;/strong&gt; en désactivant un effet à la fois. Une feuille de style injectée suffit.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Se méfier des effets multipliés&lt;/strong&gt; : un &lt;code&gt;backdrop-filter&lt;/code&gt; est gratuit sur une modale, ruineux sur cent cartes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Quand le coût est proportionnel à la taille des données&lt;/strong&gt;, optimiser chaque élément ne fait que repousser le
problème. Ne rendre que ce qui se voit le règle.&lt;/li&gt;
&lt;/ol&gt;
&lt;hr&gt;
&lt;p&gt;&lt;em&gt;Code : &lt;a href=&quot;https://tech.pokipedia.com/client/src/components/VirtualCardGrid.jsx&quot;&gt;&lt;code&gt;VirtualCardGrid.jsx&lt;/code&gt;&lt;/a&gt;,
&lt;a href=&quot;https://tech.pokipedia.com/client/src/useLasso.jsx&quot;&gt;&lt;code&gt;useLasso.jsx&lt;/code&gt;&lt;/a&gt;, &lt;a href=&quot;https://tech.pokipedia.com/client/src/pages/PullsPage.jsx&quot;&gt;&lt;code&gt;PullsPage.jsx&lt;/code&gt;&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
</content>
  </entry>
</feed>