Skip to content
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

Prevent Pre-Publish Panel from Displaying Incorrect Information After Navigating away #67010

Merged
merged 5 commits into from
Nov 19, 2024
9 changes: 6 additions & 3 deletions packages/editor/src/components/post-publish-panel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ export class PostPublishPanel extends Component {
// Automatically collapse the publish sidebar when a post
// is published and the user makes an edit.
if (
prevProps.isPublished &&
! this.props.isSaving &&
this.props.isDirty
( prevProps.isPublished &&
! this.props.isSaving &&
this.props.isDirty ) ||
! this.props.postlink
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a better check would be to see if the currentPostId changed: this.props.currentPostId !== prevProps.currentPostId, where currentPostId is select(editorStore).getCurrentPostId().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @ntsekouras, thanks for suggesting a better approach!
I have implemented the suggested changes, please have a look.

Thanks 🙌🏻

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Let's use getCurrentPostId selector though instead of getEditedPostAttribute( 'id' ) and name the prop currentPostId for clarity.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ntsekouras I have implemented the changes!
Also, can you highlight on why using getCurrentPostId is a better approach?

Thanks 🙌🏻

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Since we only want the id, getCurrentPostId returns that directly from the state whereas getEditedPostAttribute is a doing more and we don't need to fetch all the edits etc..

) {
this.props.onClose();
}
Expand Down Expand Up @@ -165,6 +166,7 @@ export default compose( [
} = select( editorStore );
const { isPublishSidebarEnabled } = select( editorStore );
const postType = getPostType( getEditedPostAttribute( 'type' ) );
const postlink = getEditedPostAttribute( 'link' );

return {
hasPublishAction:
Expand All @@ -177,6 +179,7 @@ export default compose( [
isSaving: isSavingPost() && ! isAutosavingPost(),
isSavingNonPostEntityChanges: isSavingNonPostEntityChanges(),
isScheduled: isCurrentPostScheduled(),
postlink,
};
} ),
withDispatch( ( dispatch, { isPublishSidebarEnabled } ) => {
Expand Down
Loading