mobile: fix loading note in editor from notifications

Fix a race condition where the loading note gets replaced by editor's stored state on app launch
This commit is contained in:
Ammar Ahmed
2025-12-23 12:48:29 +05:00
parent 50d0827972
commit ecf75a07e4
4 changed files with 16 additions and 3 deletions

View File

@@ -176,6 +176,7 @@ const onAppOpenedFromURL = async (event: { url: string }) => {
if (id) {
const note = await db.notes.note(id);
if (note) {
editorState().initialLoadCalled = true;
eSendEvent(eOnLoadNote, {
item: note
});

View File

@@ -664,7 +664,8 @@ export const useEditorEvents = (
if (note) {
eSendEvent(eOnLoadNote, {
item: note,
tabId: editorMessage.tabId
tabId: editorMessage.tabId,
loadedFromEditor: true
});
}
} else {
@@ -675,7 +676,8 @@ export const useEditorEvents = (
if (note) {
eSendEvent(eOnLoadNote, {
item: note,
tabId: editorMessage.tabId
tabId: editorMessage.tabId,
loadedFromEditor: true
});
}
}

View File

@@ -508,9 +508,17 @@ export const useEditor = (
newTab?: boolean;
refresh?: boolean;
searchResultIndex?: number;
loadedFromEditor?: boolean;
}) => {
loadNoteMutex.runExclusive(async () => {
if (!event) return;
if (
!event ||
(event.loadedFromEditor &&
event.item &&
event.item?.id !== useTabStore.getState().getCurrentNoteId())
) {
return;
}
if (event.blockId) {
blockIdRef.current = event.blockId;
}
@@ -719,6 +727,7 @@ export const useEditor = (
}, 300);
}
postMessage(NativeEvents.theme, theme);
console.log("load finished", event.item?.id);
});
},
[

View File

@@ -438,6 +438,7 @@ async function scheduleNotification(
async function loadNote(id: string, jump: boolean) {
if (!id || id === "notesnook_note_input") return;
editorState().initialLoadCalled = true;
const note = await db.notes.note(id);
if (!note) return;
if (!DDS.isTab && jump) {