Editor: Reset edits when navigating away from new post without saving #4539
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.
This pull request seeks to resolve an issue where navigating away from a new draft to My Sites will cause the "Add" buttons adjacent to custom post types to link incorrectly to the previously edited post.
Implementation notes:
The issue occurs in the
getEditorPath
selector, and is a result of how we treatgetEditedPost
as meaning the unsaved draft when a null post ID is passed, which is further complicated by our logic for generating an editor editor path for a new custom post type by using a null post ID. We should probably seek to create a better distinction between these use-cases, by either creating a standalonegetEditorNewPostPath
or not considering edits in generating the editor path (changed previously in 16976b3).Regardless of improvements around
getEditorPath
, it's reasonable to expect that we should be resetting unsaved draft edits when navigating away from the editor, or at the very least when navigating to a new editor draft session. The changes here add a new exit route hook, discarding post edits if the post was not saved.Note that the only post edit state currently tracked in Redux state is the post type, and that this issue does not currently affect production environments since the
getEditorPath
selector is not used in any environment aside from development.Testing instructions:
Verify that the correct "Add" link is shown for a custom post type after navigating away from the post editor.