-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Store: Reset change detection on post update #6209
Conversation
Failing tests have been resolved in 23889c8 to use platform-dependent modifier key, which makes sense since our use of mod+s in But then it makes me wonder how meta+a works in multi-selection end-to-end tests (cc @youknowriad). We have another instance of this in meta box tests. What I think is happening here (and also susceptible in this pull request) is that the Ctrl+S save isn't occurring, but the autosave kicks in 10 seconds later automatically, satisfying the previous |
editor/store/selectors.js
Outdated
@@ -88,7 +88,7 @@ export function isEditedPostNew( state ) { | |||
* @return {boolean} Whether unsaved values exist. | |||
*/ | |||
export function isEditedPostDirty( state ) { | |||
return state.editor.isDirty; | |||
return state.editor.isDirty || isSavingPost( state ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you clarify why it should return true on mid-save?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you clarify why it should return true on mid-save?
The fix here is moving the change detection reset from RESET_POST
to UPDATE_POST
, so immediately upon hitting save, before the request has finished. This means that we can track changes that occur while the save is in-flight. Conversely, we need to make sure that if the user attempts to navigate away while the save is still pending, they're notified.
Another (better?) way to express this might be to consider whether there are any transactions in redux-optimist
where isDirty: true
; i.e. is there a possibility that if the transaction (save attempt) was to be reverted (save fail), would the user be put back into a state of dirtiness?
I'd also considered if we could track changes more like what we had, with it being a condition of the current state: This is simple enough to check if there are any entries in state.editor.entries
, but state.editor.blocksByUid
and state.editor.blockOrder
is harder to track for changes (without comparing to an initial value).
Meta exists and has its own meaning in Windows (Windows key), though not always consistently applied by browsers apparently in treating https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/metaKey |
23889c8
to
978f8d5
Compare
Rebased. e7f6b1c adds a new utility for end-to-end tests, 978f8d5 avoids |
978f8d5
to
3a2e39f
Compare
@@ -89,7 +89,7 @@ export function isEditedPostNew( state ) { | |||
* @return {boolean} Whether unsaved values exist. | |||
*/ | |||
export function isEditedPostDirty( state ) { | |||
return state.editor.isDirty; | |||
return state.editor.isDirty || inSomeHistory( state, isEditedPostDirty ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is causing a regression for the post publish panel, it's getting closed right after publish
Fixes #6112
This pull request seeks to resolve an issue where changes made while a post is saving are not accurately reflected in change detection, resulting in the potential for data loss if the user attempts to navigate away after a save completes.
In doing so, it also introduces...
withChangeDetection
higher-order reducer where ignored action types may have resulted in theisDirty
value being lost.Testing instructions:
Verify that end-to-end tests pass:
Repeat steps to reproduce from #6112, verifying that the editor prompts about unsaved changes if they were introduced in the time between save start and save success.