mirror of
https://github.com/zadam/trilium.git
synced 2025-11-30 04:24:24 +01:00
fix(type_widgets): partially prevent wrong note type rendering due to async race condition
This commit is contained in:
parent
ab97068a1d
commit
fd6ad6dce3
@ -30,6 +30,7 @@ export default function NoteDetail() {
|
|||||||
const isFullHeight = checkFullHeight(noteContext, type);
|
const isFullHeight = checkFullHeight(noteContext, type);
|
||||||
const [ noteTypesToRender, setNoteTypesToRender ] = useState<{ [ key in ExtendedNoteType ]?: (props: TypeWidgetProps) => VNode }>({});
|
const [ noteTypesToRender, setNoteTypesToRender ] = useState<{ [ key in ExtendedNoteType ]?: (props: TypeWidgetProps) => VNode }>({});
|
||||||
const [ activeNoteType, setActiveNoteType ] = useState<ExtendedNoteType>();
|
const [ activeNoteType, setActiveNoteType ] = useState<ExtendedNoteType>();
|
||||||
|
const widgetRequestId = useRef(0);
|
||||||
|
|
||||||
const props: TypeWidgetProps = {
|
const props: TypeWidgetProps = {
|
||||||
note: note!,
|
note: note!,
|
||||||
@ -41,10 +42,15 @@ export default function NoteDetail() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!type) return;
|
if (!type) return;
|
||||||
|
const requestId = ++widgetRequestId.current;
|
||||||
|
|
||||||
if (!noteTypesToRender[type]) {
|
if (!noteTypesToRender[type]) {
|
||||||
getCorrespondingWidget(type).then((el) => {
|
getCorrespondingWidget(type).then((el) => {
|
||||||
if (!el) return;
|
if (!el) return;
|
||||||
|
|
||||||
|
// Ignore stale requests
|
||||||
|
if (requestId !== widgetRequestId.current) return;
|
||||||
|
|
||||||
setNoteTypesToRender(prev => ({
|
setNoteTypesToRender(prev => ({
|
||||||
...prev,
|
...prev,
|
||||||
[type]: el
|
[type]: el
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user