Fix 'Discard changes' dialog appearing even when no changes are made #3495
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.
Fixes #3491
I was unable to reproduce the issue using the provided collection or newly created profiles. However, I managed to reproduce it with some of my existing profiles, so I investigated the cause.
Firstly, I don't think the absence of
limits.newToday/reviewToday
should be the cause of the issue.When working on #3478, I recognized that some of the properties of
limits
could change during the initialization of theDailyLimits
component. ForDailyLimits
, all missing properties in the orginal config default toundefined
. Therefore, in #3478, properties with the valueundefined
are excluded when comparing orginal and current to prevent false positives.After running
git bisect
, I found that the issue has been introduced in #3442.The issue is caused by the fact that the
EasyDays
component, likeDailyLimits
, may modify the config object during its initialization.anki/ts/routes/deck-options/EasyDays.svelte
Lines 18 to 20 in f00211d
Approach in this PR
Retrieve the original configs asynchronously after all components are mounted, allowing child components to adjust the config during their initialization phase.
From testing, it appears that this only happens if the user never interacts with the webview (e.g., clicking on the webview or pressing a key) from the time the window is opened until the
Esc
key is pressed. In this case, AnkiWebView'sonEsc()
is not called, and DeckOptionsDialog'sreject()
is called directly. As a result,check_pending_changes()
is not executed.I don't think this is something that needs to be addressed, because as a practical matter it's impossible for a user to change deck options without interacting with the webview at all, and the expected behavior is for the confirmation dialog not to pop up if no changes have been made.
Apart from the above, I found another issue while investigating.
Since #3410, we use
evt.accept()
instead ofcloseEvent()
of the base class when closing the window, but it seems thatevt.accept()
does not triggerreject()
afterwards. As a result, the cleanup process withinreject()
does not run. You can confirm this issue in Anki 24.10 beta (all of 1, 2, and 3) by the fact that if you close the window without saving the config, the geometry is not saved.Approach in this PR
Call
closeEvent()
of the base class instead ofevt.accept()
.