fix(vwb): bibliothèque ne s'écrase plus au chargement
Some checks failed
security-audit / Bandit (scan statique) (push) Successful in 13s
security-audit / pip-audit (CVE dépendances) (push) Successful in 11s
security-audit / Scan secrets (grep) (push) Successful in 9s
tests / Lint (ruff + black) (push) Successful in 16s
tests / Tests unitaires (sans GPU) (push) Failing after 16s
tests / Tests sécurité (critique) (push) Has been skipped

Le useEffect(saveLibrary) se déclenchait avec library=[] avant que
loadLibraryAsync ait fini → écrasait le fichier serveur avec un
tableau vide. Ajout d'un flag libraryLoaded pour ne sauvegarder
qu'après le chargement initial.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Dom
2026-04-21 11:54:16 +02:00
parent 84181cc982
commit 4923623dd4

View File

@@ -64,6 +64,7 @@ export default function CapturePanel({
const [previewScale, setPreviewScale] = useState({ x: 1, y: 1 }); const [previewScale, setPreviewScale] = useState({ x: 1, y: 1 });
const isDebugMode = executionMode === 'debug'; const isDebugMode = executionMode === 'debug';
const [libraryLoaded, setLibraryLoaded] = useState(false);
// Charger la bibliotheque depuis le backend (prioritaire), fallback localStorage. // Charger la bibliotheque depuis le backend (prioritaire), fallback localStorage.
useEffect(() => { useEffect(() => {
@@ -77,13 +78,16 @@ export default function CapturePanel({
: item.timestamp, : item.timestamp,
})) }))
); );
setLibraryLoaded(true);
}); });
}, []); }, []);
// Sauvegarder la bibliotheque (localStorage + backend) // Sauvegarder la bibliotheque SEULEMENT après le chargement initial
useEffect(() => { useEffect(() => {
saveLibrary(library); if (libraryLoaded) {
}, [library]); saveLibrary(library);
}
}, [library, libraryLoaded]);
// Ajouter capture a la bibliotheque (thumbnail compresse JPEG 320x240) // Ajouter capture a la bibliotheque (thumbnail compresse JPEG 320x240)
useEffect(() => { useEffect(() => {