Write: redirect to fresh editor when bfcache restores published page#48705
Write: redirect to fresh editor when bfcache restores published page#48705kbrown9 wants to merge 3 commits into
Conversation
…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>
|
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 SummaryThis 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. 🤷 |
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>
allilevine
left a comment
There was a problem hiding this comment.
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>
Fixes RSM-2709
Proposed changes
isSaving=truewhile the redirect fires, a bfcache restore strands the user on a "done" page with grayed-out Save Draft and Publish buttons.pageshowevent listener that detects bfcache restoration after a publish and redirects to a fresh Write editor usinglocation.replace()to avoid creating a back-button trap.Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
/wp-admin/admin.php?page=write).Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com