-
-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Mobile (testing environment): Last editor input is lost if changes are made less than about 100ms before closing the app #11125
Comments
Does unmounting the component happen just when exiting the app, or does it happen also when exiting edit mode to save the note? |
I can see that if I add a log entry in the componentWillUnmount() function in app-mobile Note.tsx, that it gets called when exiting the note completely i.e. going back to the note list. It isn't getting called if I close the app via the Android recent list while the note is open. Should the title of this issue therefore instead be: 'Last editor input is lost if changes are made less than about 100ms before closing the note' ? Also, maybe the problem and solution outlined here could aid with a resolution for the issue? https://medium.com/@minduladilthushan/resolving-the-state-not-updating-immediately-issue-in-react-js-febf5959c0cf |
Possibly, though it depends on the cause of the issue:
|
I had a play and I was able to make your test in https://github.com/laurent22/joplin/pull/11126/files pass with a 50ms wait for jest.advanceTimersByTimeAsync. It looks like this code in Note.tsx is the cause: If I change the timeout passed to debounce as 1, then the test passes. It can be surmised that if processAllNow (called when unmounting) completes before debounce does, then the change to be added following completion of debounce will be lost. This is because the change is not added to the save action queue until after the 100 ms, and the component would have been already unmounted. So I think to fix this, in onMarkdownEditorTextChange the change needs to be made without using debounce, but instead push a slightly modified makeSaveAction which waits the 100ms before before executing it's logic. There is a risk though that if doing the delay in the action, that you can get a backlog of save action queue items because the queue runs synchronously. But maybe this could be worked around by instead of waiting 100ms explicitly, record a timestamp 100ms after the current time in the action when creating it, then only apply a delay if that time has not yet passed |
Apologies, I jumped the gun a bit. After adding some additional logging and changing the code a bit, I can confirm that a note change scheduled using debounce does indeed execute, even after componentWillUnmount and the save action queue has completed. So that is not the issue. Would it be possible with a React Native app to make some sort of visual indicator on the note screen while the note is saving, which persists onto the note list after exiting the note, until the save is completed? Or another option and maybe simpler would be to make the back button on the note (when switching from edit to to view mode) wait at intervals until the save action queue is empty, before executing the code to switch it to view mode. That way it will block the UI until all changes are saved |
I made some further tests, and it turns out there are 3 issues: Last.Input.Lost.After.Exiting.Note.Quickly.2024-11-05.21-45-23-418.mp4 |
Operating system
Linux
Joplin version
86c035c
Desktop version info
N/A
Current behaviour
Updating the mobile note editor, then quickly unmounting the component results in loss of the last-entered data.
In particular,
On a real device, this 100ms threshold may be greater.
Test case: commit.
Expected behaviour
The last change to the editor should be preserved, even if made very briefly before closing the editor.
Notes
Logs
No response
The text was updated successfully, but these errors were encountered: