-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changing the currently opened note from plugins does not refresh the note content #5955
Comments
Is this purely a plugin API issue? The same behaviour is seen when a note is modified via sync whilst it is open. |
Youre right. I think i saw some issues open relating to syncing a note while its open. |
You are right, somehow I forgot about that feature entirely as I normally only experience the issue on mobile for which it is not resolved (from what I can tell). |
I have the same issue while developing, the current workaround is using |
Ok so I looked 👀 into this. Found following:
So we can either:
So I tried the second option kinda like this (pseudocode): useEffect(() => {
const currentNote = state.notes?.find(note => note?.id === formNote?.id);
if (!currentNote) return;
setFormNote(currentNote);
}, [state.notes]); This does work in such that the note is synced after a PUT in API. Great! Maybe that helps. g2g now if I've more time I can continue looking into it |
@ThibaultJanBeyer, I think we have some code that updates the editor note when it is updated via sync. Perhaps we could use a similar hook when it's updated via PUT? |
Sounds good, I tried to find that sync code updating the note. But as I'm new to the code, @laurent22 do you mind pointing me where that is? Thank you! PS: I also checked and if I check for changes in title and body only it will work (pseudocode): useEffect(() => {
const currentNote = await Note.load(noteId);
if (!currentNote) return;
if (/* compare currentNote with formNote and they don't match */) {
await initNoteState(currentNote);
}
}, [state.notes]); Rather this or have a special hook on PUT? What do you think? |
Check syncStarted in useFormNote |
Well, the only thing that is changed by PUT is the note being saved. Which dispatches a So I can think of 2 solutions, with their respective pros and cons:
This could be a generic solution handling both, the PUT update and the SYNC update…
I guess solution 2 is the "safer" choice… g2g, let me know what you prefer |
How about pulling from the state something like props.noteUpdatedTime? (state.note[].updated_time) Then you compare that to the currently loaded note and if it differs you know it's been changed outside the editor. |
Created a PR, please check it and test all the use-cases. I ran |
… plugins or the data API does not refresh the note content Causes an infinite rendering loop when creating a new note
Unfortunately had to revert it in 34c4b83 due to infinite rendering loop. |
When modifying a note from a plugin, for example while using
joplin.data.put
, if that note is the currently opened one, the content does not update. The user must leave the note then reopen it to see the changes.Environment
Joplin version: 2.6.10
Platform: Linux
OS specifics: Fedora KDE 35
Steps to reproduce
Describe what you expected to happen
Either all Joplin APIs that change a note should trigger a UI update or the Joplin Plugin API needs to expose a function to refresh the currently opened note.
Logfile
The text was updated successfully, but these errors were encountered: