fix(editor): preload all detail SVGs on mount so re-imported reports render findings
EditorRoute used to populate detailBones lazily, inside the useEffect that fires when the user opens a detail popup. That was fine for fresh sessions, but after re-importing a PDF the store can already hold observations whose zones reference detail-popup bone ids (e.g. an ATM zone with boneId "point-mpbyo7zq" carried by the head detail SVG). Without the matching Bone in detailBones, ObservationCard.zonesWithTree could not resolve bone.fr — matchZoneFindings discarded the zone and the findings tree picker never appeared on observations whose only zones came from a detail popup. The findings were already in the store (read straight from the JSON attachment), so it looked exactly like "the pathologies don't load on re-upload" from the user side. Fix: in the species-load useEffect, fire a fetch for every species.details path in parallel and merge the parsed bones into detailBones. Each fetch has its own catch so one missing asset does not block the others. The popup-open useEffect stays as a no-op safety net (merge is idempotent thanks to the !merged.has(id) guard). Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
93294a449b
commit
1e12f2252f
1 file changed
+22
@@ -109,6 +109,28 @@ export default function EditorRoute() {
|
||||
if (!species) return
|
||||
loadSvg(species.mainSvg).then((root) => setBones(parseSvgBones(root)))
|
||||
species.findings().then((m) => setFindings(m.default))
|
||||
|
||||
// Eagerly preload every detail SVG so observation zones imported
|
||||
// from a PDF (which can carry detail-popup boneIds without the user
|
||||
// ever re-opening the popup) resolve their labels and findings
|
||||
// pickers immediately on mount. Each fetch is independent — a 404
|
||||
// on one detail asset must not prevent the others from loading.
|
||||
Object.values(species.details).forEach((path) => {
|
||||
loadSvg(path)
|
||||
.then((root) => {
|
||||
const parsed = parseSvgBones(root)
|
||||
setDetailBones((prev) => {
|
||||
const merged = new Map(prev)
|
||||
parsed.forEach((b, id) => {
|
||||
if (!merged.has(id)) merged.set(id, b)
|
||||
})
|
||||
return merged
|
||||
})
|
||||
})
|
||||
.catch((err) => {
|
||||
console.warn(`EditorRoute: failed to preload detail SVG ${path}`, err)
|
||||
})
|
||||
})
|
||||
}, [species])
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Reference in new issue
Block a user