Skip to content

Write: redirect to fresh editor when bfcache restores published page#48705

Open
kbrown9 wants to merge 3 commits into
trunkfrom
fix/write_bfcache
Open

Write: redirect to fresh editor when bfcache restores published page#48705
kbrown9 wants to merge 3 commits into
trunkfrom
fix/write_bfcache

Conversation

@kbrown9
Copy link
Copy Markdown
Member

@kbrown9 kbrown9 commented May 11, 2026

Fixes RSM-2709

Proposed changes

  • On Atomic sites, the browser's back-forward cache (bfcache) can restore the Write editor after publishing. Because the publish flow leaves isSaving=true while the redirect fires, a bfcache restore strands the user on a "done" page with grayed-out Save Draft and Publish buttons.
  • Adds a pageshow event listener that detects bfcache restoration after a publish and redirects to a fresh Write editor using location.replace() to avoid creating a back-button trap.

Related product discussion/links

  • RSM-2709

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

No.

Testing instructions

  • Go to an Atomic site with the Write editor enabled.
  • Open the Write editor (/wp-admin/admin.php?page=write).
  • Write some content, then click Publish.
  • After being redirected to the published post, click the browser's Back button.
  • Verify you land on a fresh Write editor (empty title and content, buttons enabled) — not a stale page with grayed-out buttons.
  • Click Back again and verify you navigate past the Write editor (no redirect loop).
  • On a non-Atomic (Simple) site, repeat the same steps and confirm the publish flow still works normally.

Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com

…page

On Atomic sites, the browser's back-forward cache (bfcache) can restore
the Write editor after a publish. Because the publish flow intentionally
leaves isSaving=true while the redirect fires, a bfcache restore strands
the user on a "done" page with grayed-out buttons. Listen for the
pageshow event and, when the page was restored from bfcache after a
publish, replace the history entry with a fresh editor URL so the user
is not trapped in a redirect loop.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 11, 2026

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_bfcache branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack-mu-wpcom-plugin fix/write_bfcache

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
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 11, 2026

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 May 11, 2026
@jp-launch-control
Copy link
Copy Markdown

jp-launch-control Bot commented May 11, 2026

Code Coverage Summary

This PR did not change code coverage!

That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷

Full summary · PHP report

@kbrown9 kbrown9 changed the title fix(write): redirect to fresh editor when bfcache restores published page Write: redirect to fresh editor when bfcache restores published page May 11, 2026
@kbrown9 kbrown9 added [Status] In Progress and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels May 11, 2026
Hide the page immediately before redirecting so the previously published
content does not flash briefly while the fresh editor loads.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Member

@allilevine allilevine left a comment

Choose a reason for hiding this comment

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

This fixes the issue for me on Atomic and the behavior on Simple stays the same. Should we try to hide the initial flash of the grayed out view before it refreshes? Claude suggested moving the visibility: hidden from pageshow to the existing pagehide handler so the page is already hidden when bfcache stores it:

window.addEventListener( 'pagehide', () => {                                                                                                                        
      if ( autosaveTimer ) {                                                                                                                                            
          clearInterval( autosaveTimer );                                                                                                                               
      }                                                                                                                                                                 
      if ( state.isPublished ) {                                                                                                                                        
          document.documentElement.style.visibility = 'hidden';                                                                                                       
      }
  } );

  window.addEventListener( 'pageshow', event => {                                                                                                                       
      if ( event.persisted && state.isPublished ) {
          window.location.replace( state.writeUrl );                                                                                                                    
      }                                                                                                                                                               
  } );

@kbrown9
Copy link
Copy Markdown
Member Author

kbrown9 commented May 12, 2026

This fixes the issue for me on Atomic and the behavior on Simple stays the same. Should we try to hide the initial flash of the grayed out view before it refreshes? Claude suggested moving the visibility: hidden from pageshow to the existing pagehide handler so the page is already hidden when bfcache stores it:

window.addEventListener( 'pagehide', () => {                                                                                                                        
      if ( autosaveTimer ) {                                                                                                                                            
          clearInterval( autosaveTimer );                                                                                                                               
      }                                                                                                                                                                 
      if ( state.isPublished ) {                                                                                                                                        
          document.documentElement.style.visibility = 'hidden';                                                                                                       
      }
  } );

  window.addEventListener( 'pageshow', event => {                                                                                                                       
      if ( event.persisted && state.isPublished ) {
          window.location.replace( state.writeUrl );                                                                                                                    
      }                                                                                                                                                               
  } );

Yes, nice find! I didn't notice the flash of the grayed out view when I tested. I'll give this a try.

Move document.documentElement.style.visibility = 'hidden' from the
pageshow handler to pagehide so the page is already hidden when the
browser snapshots it for bfcache. This eliminates the brief flash of
stale grayed-out content on restore.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants