fix(type_widgets): partially prevent wrong note type rendering due to async race condition

This commit is contained in:
Elian Doran 2025-11-29 12:25:15 +02:00
parent ab97068a1d
commit fd6ad6dce3
No known key found for this signature in database

View File

@ -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<ExtendedNoteType>();
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