Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full Site Editing: Overwrite theme attributes in file based templates #28207

Closed

Conversation

jeyip
Copy link
Contributor

@jeyip jeyip commented Jan 14, 2021

Description

This ticket is a follow up to #28088.

To simplify and constrain the scope of full site editing work, there was a prior decision made to assume that when we serve template files, they're always from the currently active theme. See the discussion here. There were also discussions about removing the theme attribute from file-based template parts.

Following that logic, there were questions about just stripping the theme attribute in template files entirely, and replacing them with the currently active theme. We couldn't think of valid use cases otherwise, so this PR is a proposal to ignore theme attributes from file-based templates and to replace them with the current theme's stylesheet.

Note:

I left a note in the PR description of #28088. We were were planning to remove the theme attribute entirely from all file-based template parts (and I'd say it's still worthwhile to do so). These changes accomplish the same goal, but do so in a programmatic and scalable way.

How has this been tested?

Screenshots

Types of changes

Bug fix for Automattic/wp-calypso#48145

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@github-actions
Copy link

Size Change: 0 B

Total Size: 1.28 MB

ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/annotations/index.js 3.8 kB 0 B
build/api-fetch/index.js 3.42 kB 0 B
build/autop/index.js 2.83 kB 0 B
build/blob/index.js 665 B 0 B
build/block-directory/index.js 9.07 kB 0 B
build/block-directory/style-rtl.css 1.01 kB 0 B
build/block-directory/style.css 1.01 kB 0 B
build/block-editor/index.js 121 kB 0 B
build/block-editor/style-rtl.css 11.6 kB 0 B
build/block-editor/style.css 11.6 kB 0 B
build/block-library/blocks/archives/editor-rtl.css 196 B 0 B
build/block-library/blocks/archives/editor.css 196 B 0 B
build/block-library/blocks/audio/editor-rtl.css 194 B 0 B
build/block-library/blocks/audio/editor.css 194 B 0 B
build/block-library/blocks/audio/style-rtl.css 225 B 0 B
build/block-library/blocks/audio/style.css 225 B 0 B
build/block-library/blocks/block/editor-rtl.css 283 B 0 B
build/block-library/blocks/block/editor.css 283 B 0 B
build/block-library/blocks/button/editor-rtl.css 576 B 0 B
build/block-library/blocks/button/editor.css 577 B 0 B
build/block-library/blocks/button/style-rtl.css 552 B 0 B
build/block-library/blocks/button/style.css 552 B 0 B
build/block-library/blocks/buttons/editor-rtl.css 345 B 0 B
build/block-library/blocks/buttons/editor.css 346 B 0 B
build/block-library/blocks/buttons/style-rtl.css 419 B 0 B
build/block-library/blocks/buttons/style.css 419 B 0 B
build/block-library/blocks/calendar/style-rtl.css 319 B 0 B
build/block-library/blocks/calendar/style.css 319 B 0 B
build/block-library/blocks/categories/editor-rtl.css 210 B 0 B
build/block-library/blocks/categories/editor.css 209 B 0 B
build/block-library/blocks/categories/style-rtl.css 208 B 0 B
build/block-library/blocks/categories/style.css 208 B 0 B
build/block-library/blocks/code/style-rtl.css 216 B 0 B
build/block-library/blocks/code/style.css 216 B 0 B
build/block-library/blocks/columns/editor-rtl.css 300 B 0 B
build/block-library/blocks/columns/editor.css 299 B 0 B
build/block-library/blocks/columns/style-rtl.css 529 B 0 B
build/block-library/blocks/columns/style.css 528 B 0 B
build/block-library/blocks/cover/editor-rtl.css 524 B 0 B
build/block-library/blocks/cover/editor.css 522 B 0 B
build/block-library/blocks/cover/style-rtl.css 1.3 kB 0 B
build/block-library/blocks/cover/style.css 1.3 kB 0 B
build/block-library/blocks/embed/editor-rtl.css 594 B 0 B
build/block-library/blocks/embed/editor.css 595 B 0 B
build/block-library/blocks/embed/style-rtl.css 489 B 0 B
build/block-library/blocks/embed/style.css 489 B 0 B
build/block-library/blocks/file/editor-rtl.css 314 B 0 B
build/block-library/blocks/file/editor.css 313 B 0 B
build/block-library/blocks/file/style-rtl.css 352 B 0 B
build/block-library/blocks/file/style.css 352 B 0 B
build/block-library/blocks/freeform/editor-rtl.css 2.55 kB 0 B
build/block-library/blocks/freeform/editor.css 2.55 kB 0 B
build/block-library/blocks/gallery/editor-rtl.css 749 B 0 B
build/block-library/blocks/gallery/editor.css 750 B 0 B
build/block-library/blocks/gallery/style-rtl.css 1.17 kB 0 B
build/block-library/blocks/gallery/style.css 1.17 kB 0 B
build/block-library/blocks/group/editor-rtl.css 433 B 0 B
build/block-library/blocks/group/editor.css 432 B 0 B
build/block-library/blocks/group/style-rtl.css 190 B 0 B
build/block-library/blocks/group/style.css 190 B 0 B
build/block-library/blocks/heading/editor-rtl.css 248 B 0 B
build/block-library/blocks/heading/editor.css 248 B 0 B
build/block-library/blocks/heading/style-rtl.css 212 B 0 B
build/block-library/blocks/heading/style.css 212 B 0 B
build/block-library/blocks/html/editor-rtl.css 384 B 0 B
build/block-library/blocks/html/editor.css 385 B 0 B
build/block-library/blocks/image/editor-rtl.css 801 B 0 B
build/block-library/blocks/image/editor.css 800 B 0 B
build/block-library/blocks/image/style-rtl.css 569 B 0 B
build/block-library/blocks/image/style.css 570 B 0 B
build/block-library/blocks/latest-comments/editor-rtl.css 277 B 0 B
build/block-library/blocks/latest-comments/editor.css 275 B 0 B
build/block-library/blocks/latest-comments/style-rtl.css 382 B 0 B
build/block-library/blocks/latest-comments/style.css 382 B 0 B
build/block-library/blocks/latest-posts/editor-rtl.css 254 B 0 B
build/block-library/blocks/latest-posts/editor.css 254 B 0 B
build/block-library/blocks/latest-posts/style-rtl.css 634 B 0 B
build/block-library/blocks/latest-posts/style.css 634 B 0 B
build/block-library/blocks/list/editor-rtl.css 203 B 0 B
build/block-library/blocks/list/editor.css 203 B 0 B
build/block-library/blocks/list/style-rtl.css 201 B 0 B
build/block-library/blocks/list/style.css 201 B 0 B
build/block-library/blocks/media-text/editor-rtl.css 311 B 0 B
build/block-library/blocks/media-text/editor.css 311 B 0 B
build/block-library/blocks/media-text/style-rtl.css 642 B 0 B
build/block-library/blocks/media-text/style.css 640 B 0 B
build/block-library/blocks/more/editor-rtl.css 545 B 0 B
build/block-library/blocks/more/editor.css 545 B 0 B
build/block-library/blocks/navigation-link/editor-rtl.css 503 B 0 B
build/block-library/blocks/navigation-link/editor.css 504 B 0 B
build/block-library/blocks/navigation-link/style-rtl.css 805 B 0 B
build/block-library/blocks/navigation-link/style.css 803 B 0 B
build/block-library/blocks/navigation/editor-rtl.css 1.38 kB 0 B
build/block-library/blocks/navigation/editor.css 1.38 kB 0 B
build/block-library/blocks/navigation/style-rtl.css 289 B 0 B
build/block-library/blocks/navigation/style.css 289 B 0 B
build/block-library/blocks/nextpage/editor-rtl.css 507 B 0 B
build/block-library/blocks/nextpage/editor.css 507 B 0 B
build/block-library/blocks/paragraph/editor-rtl.css 236 B 0 B
build/block-library/blocks/paragraph/editor.css 236 B 0 B
build/block-library/blocks/paragraph/style-rtl.css 390 B 0 B
build/block-library/blocks/paragraph/style.css 391 B 0 B
build/block-library/blocks/post-author/editor-rtl.css 329 B 0 B
build/block-library/blocks/post-author/editor.css 329 B 0 B
build/block-library/blocks/post-author/style-rtl.css 303 B 0 B
build/block-library/blocks/post-author/style.css 303 B 0 B
build/block-library/blocks/post-comments-form/style-rtl.css 358 B 0 B
build/block-library/blocks/post-comments-form/style.css 358 B 0 B
build/block-library/blocks/post-content/editor-rtl.css 262 B 0 B
build/block-library/blocks/post-content/editor.css 262 B 0 B
build/block-library/blocks/post-excerpt/editor-rtl.css 206 B 0 B
build/block-library/blocks/post-excerpt/editor.css 206 B 0 B
build/block-library/blocks/post-featured-image/editor-rtl.css 453 B 0 B
build/block-library/blocks/post-featured-image/editor.css 453 B 0 B
build/block-library/blocks/post-featured-image/style-rtl.css 223 B 0 B
build/block-library/blocks/post-featured-image/style.css 223 B 0 B
build/block-library/blocks/preformatted/style-rtl.css 193 B 0 B
build/block-library/blocks/preformatted/style.css 193 B 0 B
build/block-library/blocks/pullquote/editor-rtl.css 304 B 0 B
build/block-library/blocks/pullquote/editor.css 304 B 0 B
build/block-library/blocks/pullquote/style-rtl.css 428 B 0 B
build/block-library/blocks/pullquote/style.css 428 B 0 B
build/block-library/blocks/query-loop/editor-rtl.css 217 B 0 B
build/block-library/blocks/query-loop/editor.css 216 B 0 B
build/block-library/blocks/query-loop/style-rtl.css 427 B 0 B
build/block-library/blocks/query-loop/style.css 429 B 0 B
build/block-library/blocks/query/editor-rtl.css 279 B 0 B
build/block-library/blocks/query/editor.css 279 B 0 B
build/block-library/blocks/quote/editor-rtl.css 195 B 0 B
build/block-library/blocks/quote/editor.css 195 B 0 B
build/block-library/blocks/quote/style-rtl.css 284 B 0 B
build/block-library/blocks/quote/style.css 285 B 0 B
build/block-library/blocks/rss/editor-rtl.css 307 B 0 B
build/block-library/blocks/rss/editor.css 309 B 0 B
build/block-library/blocks/rss/style-rtl.css 394 B 0 B
build/block-library/blocks/rss/style.css 393 B 0 B
build/block-library/blocks/search/editor-rtl.css 285 B 0 B
build/block-library/blocks/search/editor.css 285 B 0 B
build/block-library/blocks/search/style-rtl.css 454 B 0 B
build/block-library/blocks/search/style.css 456 B 0 B
build/block-library/blocks/separator/editor-rtl.css 229 B 0 B
build/block-library/blocks/separator/editor.css 229 B 0 B
build/block-library/blocks/separator/style-rtl.css 352 B 0 B
build/block-library/blocks/separator/style.css 352 B 0 B
build/block-library/blocks/shortcode/editor-rtl.css 603 B 0 B
build/block-library/blocks/shortcode/editor.css 603 B 0 B
build/block-library/blocks/site-logo/editor-rtl.css 321 B 0 B
build/block-library/blocks/site-logo/editor.css 321 B 0 B
build/block-library/blocks/site-logo/style-rtl.css 238 B 0 B
build/block-library/blocks/site-logo/style.css 238 B 0 B
build/block-library/blocks/social-link/editor-rtl.css 283 B 0 B
build/block-library/blocks/social-link/editor.css 283 B 0 B
build/block-library/blocks/social-links/editor-rtl.css 811 B 0 B
build/block-library/blocks/social-links/editor.css 810 B 0 B
build/block-library/blocks/social-links/style-rtl.css 1.44 kB 0 B
build/block-library/blocks/social-links/style.css 1.44 kB 0 B
build/block-library/blocks/spacer/editor-rtl.css 416 B 0 B
build/block-library/blocks/spacer/editor.css 416 B 0 B
build/block-library/blocks/spacer/style-rtl.css 184 B 0 B
build/block-library/blocks/spacer/style.css 184 B 0 B
build/block-library/blocks/subhead/editor-rtl.css 223 B 0 B
build/block-library/blocks/subhead/editor.css 223 B 0 B
build/block-library/blocks/subhead/style-rtl.css 210 B 0 B
build/block-library/blocks/subhead/style.css 210 B 0 B
build/block-library/blocks/table/editor-rtl.css 593 B 0 B
build/block-library/blocks/table/editor.css 593 B 0 B
build/block-library/blocks/table/style-rtl.css 501 B 0 B
build/block-library/blocks/table/style.css 501 B 0 B
build/block-library/blocks/tag-cloud/editor-rtl.css 237 B 0 B
build/block-library/blocks/tag-cloud/editor.css 235 B 0 B
build/block-library/blocks/tag-cloud/style-rtl.css 221 B 0 B
build/block-library/blocks/tag-cloud/style.css 221 B 0 B
build/block-library/blocks/template-part/editor-rtl.css 714 B 0 B
build/block-library/blocks/template-part/editor.css 714 B 0 B
build/block-library/blocks/text-columns/editor-rtl.css 220 B 0 B
build/block-library/blocks/text-columns/editor.css 220 B 0 B
build/block-library/blocks/text-columns/style-rtl.css 283 B 0 B
build/block-library/blocks/text-columns/style.css 283 B 0 B
build/block-library/blocks/verse/editor-rtl.css 194 B 0 B
build/block-library/blocks/verse/editor.css 194 B 0 B
build/block-library/blocks/verse/style-rtl.css 215 B 0 B
build/block-library/blocks/verse/style.css 215 B 0 B
build/block-library/blocks/video/editor-rtl.css 617 B 0 B
build/block-library/blocks/video/editor.css 617 B 0 B
build/block-library/blocks/video/style-rtl.css 303 B 0 B
build/block-library/blocks/video/style.css 304 B 0 B
build/block-library/common-rtl.css 1.01 kB 0 B
build/block-library/common.css 1.01 kB 0 B
build/block-library/editor-rtl.css 8.96 kB 0 B
build/block-library/editor.css 8.96 kB 0 B
build/block-library/index.js 142 kB 0 B
build/block-library/style-rtl.css 8.52 kB 0 B
build/block-library/style.css 8.53 kB 0 B
build/block-library/theme-rtl.css 860 B 0 B
build/block-library/theme.css 860 B 0 B
build/block-serialization-default-parser/index.js 1.88 kB 0 B
build/block-serialization-spec-parser/index.js 3.06 kB 0 B
build/blocks/index.js 48.1 kB 0 B
build/components/index.js 173 kB 0 B
build/components/style-rtl.css 15.5 kB 0 B
build/components/style.css 15.5 kB 0 B
build/compose/index.js 11.2 kB 0 B
build/core-data/index.js 15.2 kB 0 B
build/data-controls/index.js 829 B 0 B
build/data/index.js 8.97 kB 0 B
build/date/index.js 31.8 kB 0 B
build/deprecated/index.js 768 B 0 B
build/dom-ready/index.js 571 B 0 B
build/dom/index.js 4.95 kB 0 B
build/edit-navigation/index.js 11.1 kB 0 B
build/edit-navigation/style-rtl.css 938 B 0 B
build/edit-navigation/style.css 944 B 0 B
build/edit-post/index.js 306 kB 0 B
build/edit-post/style-rtl.css 6.56 kB 0 B
build/edit-post/style.css 6.55 kB 0 B
build/edit-site/index.js 24.2 kB 0 B
build/edit-site/style-rtl.css 4 kB 0 B
build/edit-site/style.css 4 kB 0 B
build/edit-widgets/index.js 23.6 kB 0 B
build/edit-widgets/style-rtl.css 3.16 kB 0 B
build/edit-widgets/style.css 3.16 kB 0 B
build/editor/editor-styles-rtl.css 476 B 0 B
build/editor/editor-styles.css 478 B 0 B
build/editor/index.js 41.9 kB 0 B
build/editor/style-rtl.css 3.89 kB 0 B
build/editor/style.css 3.89 kB 0 B
build/element/index.js 4.62 kB 0 B
build/escape-html/index.js 735 B 0 B
build/format-library/index.js 6.75 kB 0 B
build/format-library/style-rtl.css 620 B 0 B
build/format-library/style.css 621 B 0 B
build/hooks/index.js 2.27 kB 0 B
build/html-entities/index.js 623 B 0 B
build/i18n/index.js 3.57 kB 0 B
build/is-shallow-equal/index.js 698 B 0 B
build/keyboard-shortcuts/index.js 2.54 kB 0 B
build/keycodes/index.js 1.94 kB 0 B
build/list-reusable-blocks/index.js 3.15 kB 0 B
build/list-reusable-blocks/style-rtl.css 629 B 0 B
build/list-reusable-blocks/style.css 628 B 0 B
build/media-utils/index.js 5.31 kB 0 B
build/notices/index.js 1.86 kB 0 B
build/nux/index.js 3.42 kB 0 B
build/nux/style-rtl.css 731 B 0 B
build/nux/style.css 727 B 0 B
build/plugins/index.js 2.54 kB 0 B
build/primitives/index.js 1.43 kB 0 B
build/priority-queue/index.js 789 B 0 B
build/redux-routine/index.js 2.84 kB 0 B
build/reusable-blocks/index.js 2.91 kB 0 B
build/rich-text/index.js 13.5 kB 0 B
build/server-side-render/index.js 2.77 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.27 kB 0 B
build/url/index.js 3.01 kB 0 B
build/viewport/index.js 1.85 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.22 kB 0 B

compressed-size-action

@@ -122,7 +122,6 @@ function _inject_theme_attribute_in_content( $template_content, $theme ) {
foreach ( $template_blocks as $key => $block ) {
if (
'core/template-part' === $block['blockName'] &&
! isset( $block['attrs']['theme'] ) &&
Copy link
Contributor Author

@jeyip jeyip Jan 14, 2021

Choose a reason for hiding this comment

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

Note:

If we remove this line of code, we will always ignore theme attributes provided by file based templates and replace it with the current theme's stylesheet.

Choose a reason for hiding this comment

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

How is this different to what #28131 does? It appears this forces the block attribute to always have the same value. Isn't that the same as removing support altogether?

Copy link
Contributor Author

@jeyip jeyip Jan 14, 2021

Choose a reason for hiding this comment

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

How is this different to what #28131 does?

From what I understand about #28131, it attempts to do away with the theme attribute entirely. (Definitely let me know if I'm misreading!)

With these code changes, the theme attribute itself is still being utilized. We're just:

  • stripping theme attributes provided by file-based templates
  • replacing the old theme attribute with a new one ( the current theme's stylesheet )

We're still relying on theme attributes to query for and to load templates/ template parts.

Choose a reason for hiding this comment

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

the theme attribute itself is still being utilized.

We're still relying on theme attributes

Is it? Are you? If I am running a theme my-theme, then any of these will end up resolving in the same way:

<!-- wp:template-part {"slug":"header","theme":"my-theme"} /-->
<!-- wp:template-part {"slug":"header"} /-->
<!-- wp:template-part {"slug":"header","theme":"I can put anything at all in here and it will resolve the same"} /-->

So, the question is, what effect does the attribute have?

Copy link
Contributor Author

@jeyip jeyip Jan 15, 2021

Choose a reason for hiding this comment

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

Thanks for the question! I'm trying to make sure I understand you correctly, so this answer is a little verbose. Just did some quick tests in my local environment to double check, but here's what I see when working with theme provided, file-based templates.

Without this PR applied:

// Loads as long as the theme we're referencing lives in the root of the theme directory (wp-content/themes)
<!-- wp:template-part {"slug":"header","theme":"my-theme"} /-->

// Loads properly because of the changes in #28088
<!-- wp:template-part {"slug":"header"} /--> // 

// Does not load
<!-- wp:template-part {"slug":"header","theme":"I can put anything at all in here and it will resolve the same"} /-->

With this PR applied:

// Loads properly
<!-- wp:template-part {"slug":"header","theme":"my-theme"} /-->

// Loads properly
<!-- wp:template-part {"slug":"header"} /--> // 

// Loads properly
<!-- wp:template-part {"slug":"header","theme":"I can put anything at all in here and it will resolve the same"} /-->

I believe you're trying to comment on what happens when we apply this PR, and you're saying that, regardless of what we use as a theme attribute, the file based template part still loads. It appears as if, when provided by theme files, the theme attribute no longer matters.

If this is what you mean, then yes, the intention of these code changes is to ignore any theme attributes defined in file-based templates. These changes, however, only affects file-based templates (see here), and wouldn't change how customized template theme attributes are handled (see here). That is to say, we wouldn't be stripping theme attributes from user-customized and saved templates.

In that sense, we're not removing support for block attributes.

Choose a reason for hiding this comment

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

@jeyip Your explanation makes total sense and you did understand correctly, although I'm not sure "stripping" is the correct description of what this patch does. It's more a case of "overwriting" or "overriding" the value of the attribute with the active theme.

You clarified this wouldn't apply to user-customised templates, but I've noticed that the present version of the master branch actually has no UI to vary the value from the active theme anyway. It can only be done through code view.

Furthermore, as I mentioned in this comment, it would be very difficult to build a useful UI for varying the theme value:

The problem with reinstating the theme reference into the endpoint is it would make it extremely difficult to list out the "active" template-parts (in the site editor, for example) without listing out every template-part from every theme.

In other words, by continuing support for the theme attribute, you're only providing immediate support for users who know how to use the editor's code view, and no one presently knows how any potential future UI will work or whether it will eventuate at all.

I guess it's up to you whether you're OK with this, but it seems to me like a dysfunctional way to run the project. Maybe you weren't aware of some of these points.

Copy link
Contributor Author

@jeyip jeyip Jan 15, 2021

Choose a reason for hiding this comment

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

although I'm not sure "stripping" is the correct description of what this patch does. It's more a case of "overwriting" or "overriding" the value of the attribute with the active theme.

Good point! I changed the PR title to reflect this.

You clarified this wouldn't apply to user-customised templates, but I've noticed that the present version of the master branch actually has no UI to vary the value from the active theme anyway. It can only be done through code view.

I think I follow. Currently, the theme attribute for user-customized template parts is set through the "code view" in the editor, and is always assigned the currently active theme.

Furthermore, as I mentioned in this comment, it would be very difficult to build a useful UI for varying the theme value:

I'm not sure I follow this. 🤔 Could you elaborate on why we'd want to vary the theme value? I think you're talking about giving users themselves the ability to assign theme attributes to the template part, but I'm not certain.

Choose a reason for hiding this comment

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

Could you elaborate on why we'd want to vary the theme value?

Ostensibly, for requesting template parts from themes other than the active one.

@jeyip jeyip marked this pull request as draft January 14, 2021 22:34
@jeyip jeyip requested a review from youknowriad January 15, 2021 03:03
@jeyip jeyip changed the title Full Site Editing: Strip theme attributes from file based templates Full Site Editing: Overwrite theme attributes from file based templates Jan 15, 2021
@jeyip jeyip changed the title Full Site Editing: Overwrite theme attributes from file based templates Full Site Editing: Overwrite theme attributes in file based templates Jan 15, 2021
Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

I'm not sure I agree with this change because it gives the wrong signal to the theme authors: It tells them you can do whatever you want in the theme attribute, It doesn't matter.

I wonder if a better approach would be to actually trigger an error if it's not empty (at least for the time being)

@david-szabo97
Copy link
Member

I'm not sure I agree with this change because it gives the wrong signal to the theme authors: It tells them you can do whatever you want in the theme attribute, It doesn't matter.

I wonder if a better approach would be to actually trigger an error if it's not empty (at least for the time being)

What if we could remap template parts in the block editor? We could show them as "Templart part couldn't be found" rather than an infinitely loading spinner. With a "Locate" button next to the error, serving the purpose of choosing an existing template part from a popover. I think this would be a good user experience.

It reminds me of Photoshop or any video editing software - if a file is missing that's referenced in the project, you can "locate" them manually. If a font is missing in Photoshop, it warns you and you can address it.

@youknowriad
Copy link
Contributor

youknowriad commented Jan 15, 2021

We could show them as "Templart part couldn't be found" rather than an infinitely loading spinner

Oh defintely, I just pushed a similar fix for Reusable blocks lately, I wasn't aware it happened in template parts too. #28126

@Addison-Stavlo
Copy link
Contributor

Addison-Stavlo commented Jan 15, 2021

I'm not sure I agree with this change because it gives the wrong signal to the theme authors: It tells them you can do whatever you want in the theme attribute, It doesn't matter.

I think this would be fair if the documentation is updated to reflect that attribute is not intended for markup. Throwing the error when its non-empty may be appropriate as well. But all in all, there is nothing a theme developer can set a theme attribute to that would be accurate and consistently functional.

@vindl
Copy link
Member

vindl commented Jan 20, 2021

I wonder if a better approach would be to actually trigger an error if it's not empty (at least for the time being)

This sounds fine to me.

I think this would be fair if the documentation is updated to reflect that attribute is not intended for markup.

I think that the documentation should be updated regardless of what we decide here.

@@ -87,14 +87,6 @@ function test_inject_theme_attribute_in_content() {
);
$this->assertEquals( $expected, $template_content );

// Does not inject theme when there is an existing theme attribute.
$content_with_existing_theme_attribute = '<!-- wp:template-part {"slug":"header","theme":"fake-theme","align":"full", "tagName":"header","className":"site-header"} /-->';
Copy link
Member

Choose a reason for hiding this comment

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

Instead of deleting this would it make sense to update it and test the case where theme attribute is not provided?

Base automatically changed from master to trunk March 1, 2021 15:45
@jeyip
Copy link
Contributor Author

jeyip commented Jun 7, 2021

Closing this for now, but we can reopen if a concrete use case for overwriting theme attributes from files arises

@jeyip jeyip closed this Jun 7, 2021
@Copons Copons deleted the try/stripping_theme_attributes_from_file_based_templates branch June 9, 2021 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants