Skip to content

Fix: Clear tweet text field only after post publish completes in block editor - #378

Merged
iamdharmesh merged 2 commits into
developfrom
fix/custom-message-reset-before-tweet-post
Jul 30, 2025
Merged

Fix: Clear tweet text field only after post publish completes in block editor#378
iamdharmesh merged 2 commits into
developfrom
fix/custom-message-reset-before-tweet-post

Conversation

@chandrapatel

@chandrapatel chandrapatel commented Jul 13, 2025

Copy link
Copy Markdown
Contributor

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:

  • 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.

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

Fixed - Clear tweet text field only after post publish completes in block editor.

Credits

Props @iamdharmesh @chandrapatel

Checklist:

…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.
@chandrapatel
chandrapatel requested a review from iamdharmesh July 13, 2025 16:59
@github-actions github-actions Bot added this to the 2.3.1 milestone Jul 13, 2025
@github-actions github-actions Bot added the needs:code-review This requires code review. label Jul 13, 2025
@dkotter dkotter modified the milestones: 2.3.1, 2.4.0 Jul 14, 2025

@iamdharmesh iamdharmesh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the PR @chandrapatel. Code looks good and it tests well.

@github-project-automation github-project-automation Bot moved this from Code Review to QA Testing in Open Source Practice Jul 30, 2025
@iamdharmesh
iamdharmesh merged commit 23e772e into develop Jul 30, 2025
1 check passed
@iamdharmesh
iamdharmesh deleted the fix/custom-message-reset-before-tweet-post branch July 30, 2025 10:26
@github-project-automation github-project-automation Bot moved this from QA Testing to Done in Open Source Practice Jul 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs:code-review This requires code review.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants