mirror of
https://github.com/zadam/trilium.git
synced 2025-11-30 04:24:24 +01:00
fix(type_widgets): read-only text sometimes rendering wrong blob
This commit is contained in:
parent
12abdcaf6c
commit
80627997d1
@ -461,27 +461,31 @@ export function useNoteLabelInt(note: FNote | undefined | null, labelName: Filte
|
|||||||
|
|
||||||
export function useNoteBlob(note: FNote | null | undefined, componentId?: string): FBlob | null | undefined {
|
export function useNoteBlob(note: FNote | null | undefined, componentId?: string): FBlob | null | undefined {
|
||||||
const [ blob, setBlob ] = useState<FBlob | null>();
|
const [ blob, setBlob ] = useState<FBlob | null>();
|
||||||
|
const requestIdRef = useRef(0);
|
||||||
|
|
||||||
function refresh() {
|
async function refresh() {
|
||||||
note?.getBlob().then(setBlob);
|
const requestId = ++requestIdRef.current;
|
||||||
|
const newBlob = await note?.getBlob();
|
||||||
|
|
||||||
|
// Only update if this is the latest request.
|
||||||
|
if (requestId === requestIdRef.current) {
|
||||||
|
setBlob(newBlob);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(refresh, [ note?.noteId ]);
|
useEffect(() => { refresh() }, [ note?.noteId ]);
|
||||||
useTriliumEvent("entitiesReloaded", ({ loadResults }) => {
|
useTriliumEvent("entitiesReloaded", ({ loadResults }) => {
|
||||||
if (!note) return;
|
if (!note) return;
|
||||||
|
|
||||||
// Check if the note was deleted.
|
// Check if the note was deleted.
|
||||||
if (loadResults.getEntityRow("notes", note.noteId)?.isDeleted) {
|
if (loadResults.getEntityRow("notes", note.noteId)?.isDeleted) {
|
||||||
|
requestIdRef.current++; // invalidate pending results
|
||||||
setBlob(null);
|
setBlob(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if a revision occurred.
|
if (loadResults.hasRevisionForNote(note.noteId) ||
|
||||||
if (loadResults.hasRevisionForNote(note.noteId)) {
|
loadResults.isNoteContentReloaded(note.noteId, componentId)) {
|
||||||
refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (loadResults.isNoteContentReloaded(note.noteId, componentId)) {
|
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user