From 1bbbe842b57528e0d7a3939b21cbd3af46aaa813 Mon Sep 17 00:00:00 2001 From: Manus Date: Fri, 30 Jan 2026 09:09:14 -0500 Subject: [PATCH] =?UTF-8?q?Checkpoint:=20R=C3=A9solution=20d=C3=A9finitive?= =?UTF-8?q?=20de=20la=20latence=20d'affichage=20du=20message=20d'upload=20?= =?UTF-8?q?:=20utilisation=20de=20flushSync()=20de=20React=20DOM=20pour=20?= =?UTF-8?q?forcer=20un=20rendu=20synchrone=20et=20imm=C3=A9diat=20de=20l'i?= =?UTF-8?q?nterface=20avant=20le=20traitement=20du=20fichier.=20L'animatio?= =?UTF-8?q?n=20"Upload=20en=20cours..."=20s'affiche=20maintenant=20instant?= =?UTF-8?q?an=C3=A9ment=20d=C3=A8s=20la=20s=C3=A9lection=20du=20fichier,?= =?UTF-8?q?=20sans=20aucune=20latence.=20D=C3=A9ploy=C3=A9=20sur=20le=20VP?= =?UTF-8?q?S=20de=20production.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/pages/AdminGestionAttestations.tsx | 19 +++++++++++-------- todo.md | 2 ++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/client/src/pages/AdminGestionAttestations.tsx b/client/src/pages/AdminGestionAttestations.tsx index 07b619e..af0eb83 100644 --- a/client/src/pages/AdminGestionAttestations.tsx +++ b/client/src/pages/AdminGestionAttestations.tsx @@ -1,4 +1,5 @@ import { useState, useMemo, useEffect } from "react"; +import { flushSync } from "react-dom"; import { trpc } from "@/lib/trpc"; import DashboardLayout from "@/components/DashboardLayout"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; @@ -179,7 +180,7 @@ function UploadAttestationDialog({ accept=".pdf" className="hidden" disabled={uploading} - onChange={async (e) => { + onChange={(e) => { const file = e.target.files?.[0]; if (!file) return; @@ -195,14 +196,15 @@ function UploadAttestationDialog({ return; } - // Afficher immédiatement l'état de chargement - setUploading(true); - setUploadProgress(0); + // Forcer le rendu synchrone de l'interface AVANT de démarrer l'upload + flushSync(() => { + setUploading(true); + setUploadProgress(0); + }); - // Attendre que React mette à jour l'interface avant de démarrer l'upload - await new Promise(resolve => setTimeout(resolve, 50)); - - try { + // Démarrer l'upload de manière asynchrone + (async () => { + try { const formData = new FormData(); formData.append('file', file); @@ -240,6 +242,7 @@ function UploadAttestationDialog({ } finally { setUploading(false); } + })(); // Fermer et exécuter la fonction async }} /> diff --git a/todo.md b/todo.md index 4120591..7be0528 100644 --- a/todo.md +++ b/todo.md @@ -1474,3 +1474,5 @@ - [x] Améliorer le feedback visuel pendant le chargement du fichier d'attestation (indicateur immédiat) - [x] Corriger la latence d'affichage du message d'upload (forcer le rendu avant traitement) + +- [x] Restructurer le flux d'upload avec useEffect pour affichage immédiat