Fix: Clear tweet text field only after post publish completes in block editor - #378
Merged
Merged
Conversation
…k editor Previously, the tweet text field was cleared as soon as the post status changed to 'publish' in the block editor. However, the status is set optimistically before the actual publish request completes, which could result in the custom tweet message being cleared before it is used for sharing to Twitter/X. This update: - Uses the isPublishingPost selector to accurately detect when the post is being published. - Tracks the previous value of isPublishingPost using useRef to detect the transition from publishing to not publishing. - Clears the tweet text field only after the publish request has fully completed and the post is actually published. - Adds a code comment explaining the use of useRef for tracking the previous publishing state. This ensures the custom tweet message is available for use when the post is published and only resets after the publish action is truly complete.
iamdharmesh
approved these changes
Jul 30, 2025
iamdharmesh
left a comment
Member
There was a problem hiding this comment.
Thanks for the PR @chandrapatel. Code looks good and it tests well.
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.
Description of the Change
Previously, the tweet text field was cleared as soon as the post status changed to 'publish' in the block editor. However, the status is set optimistically before the actual publish request completes, which could result in the custom tweet message being cleared before it is used for sharing to Twitter/X.
This update:
isPublishingPostselector to accurately detect when the post is being published.isPublishingPostusinguseRefto detect the transition from publishing to not publishing.useReffor tracking the previous publishing state.This ensures the custom tweet message is available for use when the post is published and only resets after the publish action is truly complete.
How to test the Change
This issue occurs only when the REST API request to publish a post is delayed. To reproduce it, add sleep(10) to the publish_tweet() function and then attempt to use a custom tweet message. The custom message will not be applied when sharing the post on X/Twitter.
Changelog Entry
Credits
Props @iamdharmesh @chandrapatel
Checklist: