Skip to content

Edit Post: Fix template part reload error by preserving original post URL - #79742

Open
sarthaknagoshe2002 wants to merge 2 commits into
WordPress:trunkfrom
sarthaknagoshe2002:fix/issue-72733
Open

Edit Post: Fix template part reload error by preserving original post URL#79742
sarthaknagoshe2002 wants to merge 2 commits into
WordPress:trunkfrom
sarthaknagoshe2002:fix/issue-72733

Conversation

@sarthaknagoshe2002

Copy link
Copy Markdown
Contributor

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 BrowserURL component 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 because post.php is strictly designed for standard post types, not wp_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 BrowserURL component within the edit-post package to detect when the editor shifts into a template or template part context. When isTemplate is 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

  1. Open a standard Post or Page in the editor.
  2. Ensure template preview mode is active, double-click a template part (like the Header), and select "Edit" to enter focus mode.
  3. Observe the URL in your browser. Verify that it does not change to a new ID, but remains anchored to your original post.
  4. Hard refresh the page.
  5. Verify that the editor loads safely back into the original post without throwing a permission error.

Screenshots or screencast

Screen.Recording.2026-07-01.at.6.24.22.PM.mov

@github-actions github-actions Bot added the [Package] Edit Post /packages/edit-post label Jul 1, 2026
@sarthaknagoshe2002
sarthaknagoshe2002 marked this pull request as ready for review July 1, 2026 14:40
@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: sarthaknagoshe2002 <sarthaknagoshe2002@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown

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.

  • Required label: Any label starting with [Type].
  • Labels found: [Package] Edit Post.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Edit Post /packages/edit-post

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Template Part: Reloading the template part editor within the post editor throws an error

1 participant