Skip to content

fix: clear stale wpcom_user_id in logged-out Write editor to prevent anon post loss#49980

Open
allilevine wants to merge 1 commit into
trunkfrom
fix/write-anon-clear-stale-user-id
Open

fix: clear stale wpcom_user_id in logged-out Write editor to prevent anon post loss#49980
allilevine wants to merge 1 commit into
trunkfrom
fix/write-anon-clear-stale-user-id

Conversation

@allilevine

Copy link
Copy Markdown
Member

Fixes READ-574

Proposed changes

  • The anonymous (logged-out) Write editor and the Calypso /setup/write-on signup flow share the wordpress.com origin and its localStorage. Calypso bootstraps whether a visitor is logged in from the wpcom_user_id key, and the write-on flow blocks entry and redirects to My Home when it believes the visitor is already authenticated — so it never transfers the draft that Publish hands off.
  • When a prior session's logout fails to clear wpcom_user_id, a genuinely logged-out visitor is treated as authenticated and their anonymous post is silently dropped.
  • This PR clears the stale wpcom_user_id when the logged-out editor loads, so the persisted auth state matches the real (logged-out) session before the Publish handoff. The clear is scoped to that single key on purpose — clearing the whole store would also wipe the wpcom-write-anon-draft snapshot the editor just persisted. It is gated on the existing isAnon() flag, so the logged-in editor is unaffected.

Related product discussion/links

Does this pull request change what data or activity we track or use?

Yes — adds one Tracks event, wpcom_write_editor_anon_stale_user_cleared, fired only when a stale wpcom_user_id was actually found and removed on the anonymous editor. No new personal data is collected.

Testing instructions

Because the full reproduction spans the wpcom (Atlas) anonymous route and the Calypso /setup/write-on flow, the end-to-end path is exercised on wordpress.com rather than a vanilla local WordPress. The editor-side behavior was verified locally by loading the served view.js in a real browser with the anon flag set and a seeded localStorage:

  • With window.wpcomWriteIsAnon = true and a pre-seeded wpcom_user_id, the key is removed on load, the wpcom-write-anon-draft snapshot is preserved, and the wpcom_write_editor_anon_stale_user_cleared Tracks event fires.
  • With the anon flag off (logged-in editor), wpcom_user_id is left untouched and no event fires.

Full-flow check on wordpress.com:

  • While logged out, write a post in Write and click Publish; create a new account.
  • Confirm you land back in the Write editor with the post intact (not on My Home).
  • Log out, then repeat — even when a wpcom_user_id lingered in localStorage from the previous run, the post should survive signup.

The anonymous Write editor and the Calypso /setup/write-on signup flow
share the wordpress.com origin and its localStorage. Calypso bootstraps
"is this visitor logged in?" from the wpcom_user_id key, and the write-on
flow blocks entry and redirects to My Home when it thinks the visitor is
already authenticated — never transferring the handed-off draft. A
wpcom_user_id left behind by a prior session (a logout that didn't clear
it) therefore silently drops the anonymous post.

Clear the stale wpcom_user_id when the logged-out editor loads so the
persisted auth state matches the real session. Scoped to the single key
so the wpcom-write-anon-draft snapshot is preserved.

READ-574

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@allilevine allilevine self-assigned this Jun 25, 2026
@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (WordPress.com Site Helper), and enable the fix/write-anon-clear-stale-user-id branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack-mu-wpcom-plugin fix/write-anon-clear-stale-user-id

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

@github-actions github-actions Bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Jun 25, 2026
@jp-launch-control

jp-launch-control Bot commented Jun 25, 2026

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/packages/jetpack-mu-wpcom/src/features/write/view.js 0/6422 (0.00%) 0.00% 39 💔

Full summary · PHP report · JS report

Coverage check overridden by I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. .

@allilevine allilevine added the I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. label Jun 26, 2026
@allilevine allilevine marked this pull request as ready for review June 26, 2026 14:46
@allilevine allilevine requested a review from kbrown9 June 26, 2026 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. [mu wpcom Feature] Write [Package] Jetpack mu wpcom WordPress.com Features [Status] In Progress [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant