From cb1ad47cb05d51265d1b643638bd806b6cc7a2bf Mon Sep 17 00:00:00 2001 From: bchanot Date: Fri, 13 Nov 2026 15:25:22 +0100 Subject: [PATCH] fix(editor): announce a draft dropped with its tile An undo or redo that removes a reference unmounted its tile with the edit view, so the tile's announce effect never ran. The drop now speaks from onDrop itself; the citations panel, unmounting after a forced close that already named the fields, stays quiet. --- .../editor/references/CitationsPanel.tsx | 29 ++++- .../editor/references/ReferenceTile.tsx | 57 +++++++--- .../unit/editor-references-flip.test.tsx | 100 ++++++++++++++++++ 3 files changed, 170 insertions(+), 16 deletions(-) diff --git a/apps/app/src/components/editor/references/CitationsPanel.tsx b/apps/app/src/components/editor/references/CitationsPanel.tsx index 850fa572..ef6853bd 100644 --- a/apps/app/src/components/editor/references/CitationsPanel.tsx +++ b/apps/app/src/components/editor/references/CitationsPanel.tsx @@ -1,4 +1,10 @@ -import type { KeyboardEvent, RefObject } from 'react' +import { + useCallback, + useLayoutEffect, + useRef, + type KeyboardEvent, + type RefObject, +} from 'react' import type { LocalizedText, Reference } from '@faunosteo/core-wasm/types' import ActionButton from '@/components/editor/fields/ActionButton' import Icon from '@/components/ui/Icon' @@ -135,17 +141,35 @@ function MissingRow({ type Panel = ReturnType +/** + * True once the panel unmounts (its list with it). It only unmounts after a close its leave check allowed, + * which already said any refused draft (`note`). React runs a deleted parent's layout + * cleanups before its children's, so a tile's edit view reads true when it drops then. + */ +function useLeaving() { + const leaving = useRef(false) + useLayoutEffect(() => { + leaving.current = false + return () => { + leaving.current = true + } + }, []) + return useCallback(() => leaving.current, []) +} + /** One cited reference as a tile (« Modifier », « Retirer de ce constat »). */ function EntryTile({ entry, reference, panel, props, + leaving, }: { entry: CitationEntry reference: Reference panel: Panel props: Props + leaving: () => boolean }) { const { tiles, keys, citers, entries, remove } = panel const { readOnly, citedBy, navigate } = props @@ -169,6 +193,7 @@ function EntryTile({ goTo: (target) => navigate(targetOfKey(target)), registerLeave: tiles.registerLeave, takeFocus: () => tiles.takeFocus(key), + hostLeaving: leaving, }} /> ) @@ -176,6 +201,7 @@ function EntryTile({ /** The cited references as tiles, the dangling ids as rows. */ function Entries({ panel, props }: { panel: Panel; props: Props }) { + const leaving = useLeaving() return (