Skip to content

Don't resolve templates for non-queried editor entities - #81868

Open
scruffian wants to merge 6 commits into
trunkfrom
scruffian/fix/hide-show-template
Open

Don't resolve templates for non-queried editor entities#81868
scruffian wants to merge 6 commits into
trunkfrom
scruffian/fix/hide-show-template

Conversation

@scruffian

@scruffian scruffian commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

What?

Stops the lazy editor from resolving a parent template for editor entities that are not queried content: template parts, synced patterns, and navigation menus.

Why?

Those entities can be edited directly, but they do not have their own frontend template hierarchy. In the v2 site editor, this means we display the "Show template" option in the viewport dropdown.

How?

Adds a useTemplateId hook that centralizes template resolution for the lazy editor. The hook returns the edited template for wp_template, and skips entities like template parts, navigation overlays and synced patterns, which aren't part of the template heirarchy.

Testing Instructions

  1. In the v2 Site Editor, open a template part directly from the Template Parts list and confirm the device preview menu does not list "Show template".
  2. Navigate into a template part from a post or page, reload the focused URL, and confirm "Show template" stays hidden in the device preview menu.
  3. Open the command palette while editing the template part and confirm there is no unrelated "Edit template: ..." command.
  4. Repeat the same checks for a synced pattern and a navigation menu.
  5. Open a regular post or page with a template and confirm that Show template still appears and works in the device preview menu.
  6. Run npm run test:unit packages/lazy-editor/src/hooks/test/use-template-id.js.

Use of AI Tools

Codex and Claude Code were used to investigate the issue, implement and revise the approach, run verification, and draft this PR description.

@github-actions github-actions Bot added the [Package] Editor /packages/editor label Aug 20, 2026
@scruffian
scruffian marked this pull request as ready for review August 20, 2026 11:09
@github-actions

github-actions Bot commented Aug 20, 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: scruffian <scruffian@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>

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

@scruffian
scruffian marked this pull request as draft August 20, 2026 11:09
@github-actions

github-actions Bot commented Aug 20, 2026

Copy link
Copy Markdown

Size Change: +60 B (0%)

Total Size: 7.75 MB

📦 View Changed
Filename Size Change
build/modules/lazy-editor/index.min.js 15 kB +60 B (+0.4%)

compressed-size-action

@scruffian
scruffian force-pushed the scruffian/fix/hide-show-template branch 3 times, most recently from e60f235 to 2da7b5a Compare August 20, 2026 11:21
@scruffian
scruffian force-pushed the scruffian/fix/hide-show-template branch from 2da7b5a to cbbe9d2 Compare August 20, 2026 11:23
Gate the option on the edited post type alone instead of the focused
back callback, which missed template parts opened directly from the
list and reloads of a focused template part URL. Extend the exclusion
to patterns and navigation menus, which resolve a fallback template
the same way.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@scruffian scruffian changed the title Hide Show template for focused template parts Hide Show template for design post types Aug 20, 2026
The v2 site editor resolved a template ID for any edited entity, so
template parts, patterns, navigation menus, and attachments fell
through core-data's template hierarchy lookup to an unrelated fallback
template. That surfaced as a bogus Show template menu item, an Edit
template command, and the fallback template's styles applying to the
canvas. The v1 site editor guards against this in
use-resolve-edited-entity; putting the guard in getTemplateId itself
covers every caller, including edit-post's unguarded ones.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@scruffian scruffian changed the title Hide Show template for design post types Don't resolve a parent template for design post types Aug 20, 2026
@github-actions github-actions Bot added the [Package] Core data /packages/core-data label Aug 20, 2026
With getTemplateId no longer resolving a template for design post
types, the menu item's original condition already hides it in every
path that mounts the editor, so the second gate guards a state that
cannot occur.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@scruffian scruffian changed the title Don't resolve a parent template for design post types Don't resolve a parent template for entities that aren't queried content Aug 20, 2026
The v2 editor resolved a template for whatever entity it opened, so
template parts, patterns, and navigation menus fell through the
template hierarchy to an unrelated fallback. Guard it where the v1
site editor guards it, next to the resolution itself, rather than
changing what getTemplateId returns for every caller.

Attachments keep resolving, since they do have a place in the
template hierarchy.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions github-actions Bot removed [Package] Core data /packages/core-data [Package] Editor /packages/editor labels Aug 20, 2026
@scruffian scruffian changed the title Don't resolve a parent template for entities that aren't queried content Don't resolve templates for non-queried editor entities Aug 20, 2026
@scruffian scruffian self-assigned this Aug 20, 2026
@scruffian
scruffian requested a review from youknowriad August 20, 2026 13:22
@scruffian scruffian added [Type] Bug An existing feature does not function as intended [Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") labels Aug 20, 2026
* @param props.postId The ID of the edited entity.
* @return The template ID, or `undefined` when there is no template to resolve.
*/
export function useTemplateId( {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Does this actually belong in core data?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm pretty sure we have versions of this hook in a lot of places. And yes, maybe core-data is the right place for it.

@scruffian
scruffian marked this pull request as ready for review August 20, 2026 13:24
* The site editor guards the same resolution in `use-resolve-edited-entity`,
* over a longer list that also reflects which entities that editor opens.
*/
const NEVER_QUERIED_POST_TYPES = [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That name is a bit weird to me. this is more about the post type not having dedicated frontend pages? what is "queried" about?

Also isn't there already support flags for this, or is the static list mandatory.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah i don't really like the name. the original name was "post types that don't have parent templates" which I also found confusing as they do appear in templates. What about "post types not in template heirarchy"?

@aduth

aduth commented Aug 26, 2026

Copy link
Copy Markdown
Member

Hey 👋 I wanted to give you a heads-up since this pull request adds new files containing JSX.

#80123 enables an ESLint rule that requires that files containing JSX must use the .tsx file extension. This is in line with coding guidelines expecting new code to be written as TypeScript.

What you'll need to do: You'll need to rename any new files containing JSX to use the .tsx file extension. This may also require you to address type errors that were not previously caught due to the use of the .js file extension.

This comment is automated, based on pull requests with recent activity that contain affected .js or .jsx files. But if you have any questions or if I can help with the migration in any way, please let me know and I'll do my best to help!

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

Labels

[Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants