Edit Post: Fix template part reload error by preserving original post URL - #79742
Edit Post: Fix template part reload error by preserving original post URL#79742sarthaknagoshe2002 wants to merge 2 commits into
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
What?
Closes #72733
This PR prevents the browser URL from syncing to the template/template part ID when entering focus mode from within the standard post editor.
Why?
When a user edits a template part from the post editor (e.g., clicking "Edit original" on a Header), the
BrowserURLcomponent previously synced the URL to reflect the template part's internal database ID (e.g.,post.php?post=321). If the user hard-reloads the page at this point, the PHP backend crashes with a "You do not have permission" error becausepost.phpis strictly designed for standard post types, notwp_template_part.As suggested in the issue, the most acceptable and robust fallback is to simply ensure the user is returned to the post they were originally editing upon reload.
How?
Updated the
BrowserURLcomponent within theedit-postpackage to detect when the editor shifts into a template or template part context. WhenisTemplateis true, the URL synchronization hook returns early, effectively freezing the URL on the parent post (e.g.,post.php?post=636).If a user reloads the page, they are safely dropped back into the parent post editor. If they click "Back" in the UI, the editor restores seamlessly.
Testing Instructions
Screenshots or screencast
Screen.Recording.2026-07-01.at.6.24.22.PM.mov