chore(memory): LRN-010 — gate DOM-mutate effect on async-mount loaded state

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Bastien ChanotandClaude committed 2026-05-19 06:56:28 +02:00
1 parent ff7ac5969e
commit 8a2f9cc7ff
2 files changed
+9

No files matched your search

+1
View File
@@ -32,3 +32,4 @@ Parser reads data-anno-special; convention doc updated.
feat(editor): home-nav (back btn + clickable Brand link to "/") + "Modifier les infos" dialog reusing PractitionerForm/AnimalForm via draft-copy with save/cancel. 3 store setters (setPractitioner/setAnimal/setOwner), 4 setter tests. Cache re-synced on save. 100/100 tests, lint 0, typecheck clean.
- hotfix(pdf): multi-SVG observation page packed into 2-col grid; pre-rasterize → measure aspect → reserve text-area height → cell budget per row; single-SVG keeps full width; floor prevents zero-cells. Text sections now always visible. LRN-009 captured.
- hotfix(editor): zone-highlight scoped to active obs only (collapsed obs no longer leave faint 'linked'/'multi' tints). AnatomyCanvas re-paints highlights after async SVG mount so DetailModal popup zones color correctly. NewReportRoute header harmonized with editor — back btn + clickable Brand left-aligned. 3 files (hotfix cap +1, accepted). LRN-010 captured.
+8
View File
@@ -72,3 +72,11 @@ Apply: any pdf-lib heading stack (eyebrow + title or chained headings). Compute
Variable-count image blocks (N SVGs per observation) overflow page when stacked top-down because each item's height depends on its rasterized aspect ratio, unknown until after embedPng.
Order: (1) pre-rasterize every image in parallel via Promise.all, capture aspect = img.height/img.width; (2) build text sections + estimate their height with wrapLines on real font metrics; (3) reserve bottom area = MARGIN_BOTTOM + textHeight + gap, derive availH for images; (4) pick cols (1 if single image, else 2), rows = ceil(n/cols); (5) rowBudget = (availH - rows*labelGap - (rows-1)*rowGap)/rows with a min-cell floor; (6) cellH per item = min(cellW*aspect, rowBudget) — preserves aspect, capped by budget.
Apply: any pdf-lib page where image count is data-driven and text must remain visible. Never lay out images before measuring text; never embed-then-skip — embed all, then place. Min-cell floor prevents zero-height when content is dense.
---
## LRN-010 | 2026-05-19 | React effect that mutates async-appended DOM needs a "loaded" gate
Symptom: highlight effect (querySelectorAll + setAttribute) silently no-ops when sibling effect appends DOM async via loadSvg().then(append). First render: mutate-effect runs against empty container, then DOM arrives, then nothing re-paints because deps didn't change. Symptom is intermittent ("sometimes highlighted, sometimes not") — actually depends on which effect resolves first on a given mount.
Fix pattern: hold a `loadedSrc` state, set it to null at src-change, set it to src right after appendChild, and depend the mutate-effect on [data, loadedSrc, src] with guard `if (loadedSrc !== src) return`. Now the mutate-effect re-runs both on data change AND when DOM finishes mounting.
Apply: any React component that mounts external DOM async and applies attribute/style mutations in a separate effect. Includes inline SVG injection, MapLibre overlays, Lottie players. Never rely on effect ordering across an async boundary.