fix: clear stale wpcom_user_id in logged-out Write editor to prevent anon post loss#49980
fix: clear stale wpcom_user_id in logged-out Write editor to prevent anon post loss#49980allilevine wants to merge 1 commit into
Conversation
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>
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
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:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage SummaryCoverage changed in 1 file.
Full summary · PHP report · JS report Coverage check overridden by
I don't care about code coverage for this PR
|
Fixes READ-574
Proposed changes
/setup/write-onsignup flow share thewordpress.comorigin and itslocalStorage. Calypso bootstraps whether a visitor is logged in from thewpcom_user_idkey, and thewrite-onflow 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.wpcom_user_id, a genuinely logged-out visitor is treated as authenticated and their anonymous post is silently dropped.wpcom_user_idwhen 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 thewpcom-write-anon-draftsnapshot the editor just persisted. It is gated on the existingisAnon()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 stalewpcom_user_idwas 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-onflow, 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 servedview.jsin a real browser with the anon flag set and a seededlocalStorage:window.wpcomWriteIsAnon = trueand a pre-seededwpcom_user_id, the key is removed on load, thewpcom-write-anon-draftsnapshot is preserved, and thewpcom_write_editor_anon_stale_user_clearedTracks event fires.wpcom_user_idis left untouched and no event fires.Full-flow check on wordpress.com:
wpcom_user_idlingered inlocalStoragefrom the previous run, the post should survive signup.