From 8a2f9cc7ff81bbf88c8393318aafb3b3bfa25b7e Mon Sep 17 00:00:00 2001 From: Bastien Chanot Date: Tue, 19 May 2026 06:56:28 +0200 Subject: [PATCH] =?UTF-8?q?chore(memory):=20LRN-010=20=E2=80=94=20gate=20D?= =?UTF-8?q?OM-mutate=20effect=20on=20async-mount=20loaded=20state?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude --- .claude/memory/journal.md | 1 + .claude/memory/learnings.md | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/.claude/memory/journal.md b/.claude/memory/journal.md index d754eec6..88f64396 100644 --- a/.claude/memory/journal.md +++ b/.claude/memory/journal.md @@ -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. diff --git a/.claude/memory/learnings.md b/.claude/memory/learnings.md index 982d72d3..fdb550d4 100644 --- a/.claude/memory/learnings.md +++ b/.claude/memory/learnings.md @@ -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.