From fd6ad6dce338d663475bd71baa3cb5b7876af257 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 29 Nov 2025 12:25:15 +0200 Subject: [PATCH] fix(type_widgets): partially prevent wrong note type rendering due to async race condition --- apps/client/src/widgets/NoteDetail.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apps/client/src/widgets/NoteDetail.tsx b/apps/client/src/widgets/NoteDetail.tsx index e5d249b36..852bb0238 100644 --- a/apps/client/src/widgets/NoteDetail.tsx +++ b/apps/client/src/widgets/NoteDetail.tsx @@ -30,6 +30,7 @@ export default function NoteDetail() { const isFullHeight = checkFullHeight(noteContext, type); const [ noteTypesToRender, setNoteTypesToRender ] = useState<{ [ key in ExtendedNoteType ]?: (props: TypeWidgetProps) => VNode }>({}); const [ activeNoteType, setActiveNoteType ] = useState(); + const widgetRequestId = useRef(0); const props: TypeWidgetProps = { note: note!, @@ -41,10 +42,15 @@ export default function NoteDetail() { useEffect(() => { if (!type) return; + const requestId = ++widgetRequestId.current; if (!noteTypesToRender[type]) { getCorrespondingWidget(type).then((el) => { if (!el) return; + + // Ignore stale requests + if (requestId !== widgetRequestId.current) return; + setNoteTypesToRender(prev => ({ ...prev, [type]: el