Desktop, Mobile, Cli: Fix note screen is not properly refreshed when updated by the sync, when E2EE is enabled - #16179
Open
mrjo118 wants to merge 4 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR #16150 fixed an issue whereby the note viewer / editor on mobile does not get refreshed upon the open note being updated via the sync. However, this caused a regression, as it turns out the existing shared.reloadNote function does not actually work properly with notes which still have E2EE applied (which is the case immediately after a change is synced), and it simply displays a blank note viewer / editor if refreshed immediately after syncing an update to the note, where E2EE is enabled.
This PR addresses the issue by decrypting the note immediately upon reloading the note, and waiting for the decryption to complete before updating the screen. Additionally, the DecryptionWorker has been amended to avoid decrypting and re-saving the note if the latest version of the note has the encryption removed, since decrypting other items in the decryption loop. This is in order to prevent a race condition which could cause content in the editor to be lost, if the decryption worker is running slowly and takes a while to reach the note which was already decrypted. This also aids PR #16023 which also makes use of on demand decryption of E2EE encrypted notes, which will prevent the decryption worker from potentially overwriting an automatically resolved conflict.
Testing
In order to test the DecryptionWorker change, I artifically added delays for both the on demand decryption and before starting the inner loop of the DecryptionWorker after selecting the items for decryption. Using these changes locally, I could produce this race condition which I verified from the log that this occurred and did not cause any issues.
Video demonstrating the issue when a conflict refreshes the note with E2EE enabled, before the change:
Screen_Recording_20260809_234949_Joplin2.mp4
Demonstrating the issue resolved, after the change:
Screen_Recording_20260810_000501_Joplin2.mp4