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

Template Part block: Fall back to current theme if no theme attribute is given. #55217

Merged
merged 5 commits into from
Oct 12, 2023

Conversation

ockham
Copy link
Contributor

@ockham ockham commented Oct 10, 2023

Part of the task in WordPress Core seeking performance improvements:

An alternative approach to #53423.

Result of a discussion with @felixarntz, aiming to fix the performance regression re-introduced by https://core.trac.wordpress.org/changeset/56818.

What?

If a Template Part block is encountered that doesn't have a theme attribute, fall back to the current them (get_stylesheet()) instead.

Why?

This should allow removing injection of the theme attribute during rendering of the Template Part block.

How?

By falling back to the current theme (get_stylesheet()) if $attributes['theme'] isn't set.

Testing Instructions

Verify that Template Parts blocks that are part of patterns still work, both on the frontend and in the editor. Specifically, verify that there are no Template part has been deleted or is unavailable errors.

Will be followed up by a Core PR to remove theme attribute injection on the frontend.

cc/ @gziolo

@ockham ockham self-assigned this Oct 10, 2023
Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

I know this is a WIP, just sharing very early feedback here :)

packages/block-library/src/template-part/index.php Outdated Show resolved Hide resolved
packages/block-library/src/template-part/index.php Outdated Show resolved Hide resolved
gziolo and others added 2 commits October 11, 2023 08:37
Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>
@gziolo gziolo added [Block] Pattern Affects the Patterns Block [Type] Enhancement A suggestion for improvement. [Block] Template Part Affects the Template Parts Block and removed [Block] Pattern Affects the Patterns Block labels Oct 11, 2023
@gziolo
Copy link
Member

gziolo commented Oct 11, 2023

After looking at how #55217 is implemented, I think we should also remove the following line that get executed only in the Gutenberg plugin:

$content = _inject_theme_attribute_in_block_template_content( $content );

The same logic should be handled now on the front end with the fallback logic for the theme attribute in the Template Part block.

@gziolo gziolo requested a review from mikachan October 11, 2023 07:32
Copy link
Member

@mikachan mikachan left a comment

Choose a reason for hiding this comment

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

Thank you for working on this! I can confirm this fixes the original issue in #53194.

I tested using the same themes (Overlaid and Lativ) as when I tested #53423, and this PR works well 👍

dmsnell added a commit to dmsnell/wordpress-develop that referenced this pull request Oct 11, 2023
Resolves WordPress/gutenberg#55217

When rendering images with the lightbox "expand on click" function enabled,
if an image block is encountered with no image (for example, a block was
added but no image was ever selected), then WordPress would create a warning
that an "undefined array key 0" was being accessed because the server code
assumes an IMG element exists in the block's HTML.

In this patch a check is performed to ensure that an IMG block exists before
processing the block. If one isn't, for any reason, the original given HTML
for the block is passed through un-modified.

This patch needs to be backported into Gutenberg from where it's sourced
but this issue arose during the WordPress 6.4 beta testing and needs to
be resolved immediately in Core.
dmsnell added a commit to dmsnell/wordpress-develop that referenced this pull request Oct 11, 2023
Resolves WordPress/gutenberg#55217

When rendering images with the lightbox "expand on click" function enabled,
if an image block is encountered with no image (for example, a block was
added but no image was ever selected), then WordPress would create a warning
that an "undefined array key 0" was being accessed because the server code
assumes an IMG element exists in the block's HTML.

In this patch a check is performed to ensure that an IMG block exists before
processing the block. If one isn't, for any reason, the original given HTML
for the block is passed through un-modified.

This patch needs to be backported into Gutenberg from where it's sourced
but this issue arose during the WordPress 6.4 beta testing and needs to
be resolved immediately in Core.
@pbking
Copy link
Contributor

pbking commented Oct 11, 2023

Tested in all scenarios I can dream up and works as I would expect. My only suggestion is that, as @gziolo suggested, the call to _inject_theme_attribute_in_block_template_content() be removed in this change. It's unnecessary with this change.

Once that change has been made this is ready to ship.

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

Pending the additional feedback in #55217 (comment), the change so far looks good to me.

@felixarntz
Copy link
Member

Given @ockham is out today, I took the liberty of pushing the additionally requested change in 47608ff. @gziolo @pbking @mikachan Could you please take another look?

@felixarntz felixarntz marked this pull request as ready for review October 11, 2023 15:38
felixarntz added a commit to ockham/wordpress-develop that referenced this pull request Oct 11, 2023
Copy link
Member

@mikachan mikachan left a comment

Choose a reason for hiding this comment

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

LGTM and works well in my testing, thanks @felixarntz!

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

I am currently benchmarking and profiling this change further, and it seems the approach here is not right in terms of performance at least. Marking as request for changes for now, let's hold off merging at this point.

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

I have concluded my performance investigation here and left a summary in https://core.trac.wordpress.org/ticket/59583#comment:20.

TL;DR This fix makes sense and is good to merge. However, it doesn't fully address the performance issues (partly because the initial "performance win" was mostly due to the bug introduced.

I have identified another very promising performance opportunity related to this https://core.trac.wordpress.org/ticket/59600 and WordPress/wordpress-develop#5463

@felixarntz
Copy link
Member

@ockham @gziolo @mikachan I think this is good to merge. I'll leave that to you since I'm not sure on the workflow in relation to backporting to the 6.4 release, but LGTM from my end. Once backported to core, we can update WordPress/wordpress-develop#5455 accordingly.

@ockham
Copy link
Contributor Author

ockham commented Oct 12, 2023

Thanks all! I'll go ahead and merge this then; also going to mark for inclusion in WP RC.

@mikachan We need this in Core to unblock WordPress/wordpress-develop#5455. In principle, it's probably fine to land on Monday, but it might be nice to do it even earlier to give us some more time to discover any potential issues with this. Are y'all planning a package sync this week still by any chance? 😊

@ockham ockham added the Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Oct 12, 2023
@ockham ockham merged commit 1e0c9c6 into trunk Oct 12, 2023
52 checks passed
@ockham ockham deleted the try/fixing-template-part-block-theme-attr-dependency branch October 12, 2023 09:19
@@ -18,12 +18,7 @@ function render_block_core_template_part( $attributes ) {
$template_part_id = null;
$content = null;
$area = WP_TEMPLATE_PART_AREA_UNCATEGORIZED;

if ( isset( $attribues['theme'] ) ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🙈

@github-actions github-actions bot added this to the Gutenberg 16.9 milestone Oct 12, 2023
mikachan pushed a commit that referenced this pull request Oct 12, 2023
… is given. (#55217)

* Template Part block: Fall back to current theme if no theme attribute is given.
* Remove now unnecessary _inject_theme_attribute_in_template_part_block() call from pattern block.

---------

Co-authored-by: Greg Ziółkowski <grzegorz@gziolo.pl>
Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>
Co-authored-by: Felix Arntz <felixarntz@google.com>
@mikachan
Copy link
Member

I just cherry-picked this PR to the 6.4-rc1 branch to get it included in the next release: fd15da3

@mikachan mikachan removed the Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Oct 12, 2023
gziolo added a commit that referenced this pull request Oct 12, 2023
* List: fix forward merging of nested list (#55121)

* Private APIs: Update consent string for unlocking access. (#55182)

Replace the consent string with `I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress`.

* useBlockSettings: add missing useMemo dependencies (#55204)

* Remove the lightbox filter and view file when the lightbox setting is disabled. (#55120)

* Remove the filter and view file of the lightbox when the lightbox setting is disabled.

* Make sure to add filter and view file when needed.

* Fix block comment indentation.

* Patterns: Remove the version enforcement for npm in `engines` field (#55245)

* Patterns: Remove the version enforcement for npm in `engines`

* Regenerate the lock file

* Remove `@return void` from PHP function docs. (#55237)

# Conflicts:
#	packages/block-library/src/form/index.php

* Image: Disable lightbox editor UI for linked images (#55141)

* Disable lightbox UI and add help text for linked images

* Update help text

* Image: Stop crashing with Lightbox on image blocks without an image (#55269)

* Stop crashing with Lightbox on image blocks without an image

* Fix PHPCS error

* Update fullscreen icon (#55021)

* Template Part block: Fall back to current theme if no theme attribute is given. (#55217)

* Template Part block: Fall back to current theme if no theme attribute is given.
* Remove now unnecessary _inject_theme_attribute_in_template_part_block() call from pattern block.

---------

Co-authored-by: Greg Ziółkowski <grzegorz@gziolo.pl>
Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>
Co-authored-by: Felix Arntz <felixarntz@google.com>

---------

Co-authored-by: Ella <4710635+ellatrix@users.noreply.github.com>
Co-authored-by: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com>
Co-authored-by: Jarda Snajdr <jsnajdr@gmail.com>
Co-authored-by: Andrea Fercia <a.fercia@gmail.com>
Co-authored-by: Greg Ziółkowski <grzegorz@gziolo.pl>
Co-authored-by: tellthemachines <tellthemachines@users.noreply.github.com>
Co-authored-by: Artemio Morales <artemio.morales@a8c.com>
Co-authored-by: Rich Tabor <hi@richtabor.com>
Co-authored-by: Bernie Reiter <96308+ockham@users.noreply.github.com>
Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>
Co-authored-by: Felix Arntz <felixarntz@google.com>
pento pushed a commit to WordPress/wordpress-develop that referenced this pull request Oct 12, 2023
Updates the npm packages and code for:

* [WordPress/gutenberg#55121 List: fix forward merging of nested list]

* [WordPress/gutenberg#55182 Update consent string for using private APIs.]

* [WordPress/gutenberg#55204 useBlockSettings: add missing useMemo dependencies]

* [WordPress/gutenberg#55120 Remove the lightbox filter and view file when the lightbox setting is disabled.]

* [WordPress/gutenberg#55245 Patterns: Remove the version enforcement for npm in engines field]

* [WordPress/gutenberg#55237 Remove `@return void` from PHP function docs]

* [WordPress/gutenberg#55141 Image: Disable lightbox editor UI for linked images]

* [WordPress/gutenberg#55269 Image: Stop crashing with Lightbox on image blocks without an image]

* [WordPress/gutenberg#55021 Update fullscreen icon]

* [WordPress/gutenberg#55217 Template Part block: Fall back to current theme if no theme attribute is given.] This change is part of fix for a performance regression re-introduced by [56818].

References:
* [WordPress/gutenberg#55298 Gutenberg PR 55298] Cherry-pick commits

Follow-up to [56818], [56816].

Props ellatrix, peterwilsoncc, jsnajdr, afercia, gziolo, isabel_brison, artemiosans, richtabor, bernhard-reiter, flixos90, mikachan, spacedmonkey, hellofromTonya.
See #59583, #59411.

git-svn-id: https://develop.svn.wordpress.org/trunk@56849 602fd350-edb4-49c9-b593-d223f7449a82
markjaquith pushed a commit to WordPress/WordPress that referenced this pull request Oct 12, 2023
Updates the npm packages and code for:

* [WordPress/gutenberg#55121 List: fix forward merging of nested list]

* [WordPress/gutenberg#55182 Update consent string for using private APIs.]

* [WordPress/gutenberg#55204 useBlockSettings: add missing useMemo dependencies]

* [WordPress/gutenberg#55120 Remove the lightbox filter and view file when the lightbox setting is disabled.]

* [WordPress/gutenberg#55245 Patterns: Remove the version enforcement for npm in engines field]

* [WordPress/gutenberg#55237 Remove `@return void` from PHP function docs]

* [WordPress/gutenberg#55141 Image: Disable lightbox editor UI for linked images]

* [WordPress/gutenberg#55269 Image: Stop crashing with Lightbox on image blocks without an image]

* [WordPress/gutenberg#55021 Update fullscreen icon]

* [WordPress/gutenberg#55217 Template Part block: Fall back to current theme if no theme attribute is given.] This change is part of fix for a performance regression re-introduced by [56818].

References:
* [WordPress/gutenberg#55298 Gutenberg PR 55298] Cherry-pick commits

Follow-up to [56818], [56816].

Props ellatrix, peterwilsoncc, jsnajdr, afercia, gziolo, isabel_brison, artemiosans, richtabor, bernhard-reiter, flixos90, mikachan, spacedmonkey, hellofromTonya.
See #59583, #59411.
Built from https://develop.svn.wordpress.org/trunk@56849


git-svn-id: http://core.svn.wordpress.org/trunk@56361 1a063a9b-81f0-0310-95a4-ce76da25c4cd
github-actions bot pushed a commit to platformsh/wordpress-performance that referenced this pull request Oct 12, 2023
Updates the npm packages and code for:

* [WordPress/gutenberg#55121 List: fix forward merging of nested list]

* [WordPress/gutenberg#55182 Update consent string for using private APIs.]

* [WordPress/gutenberg#55204 useBlockSettings: add missing useMemo dependencies]

* [WordPress/gutenberg#55120 Remove the lightbox filter and view file when the lightbox setting is disabled.]

* [WordPress/gutenberg#55245 Patterns: Remove the version enforcement for npm in engines field]

* [WordPress/gutenberg#55237 Remove `@return void` from PHP function docs]

* [WordPress/gutenberg#55141 Image: Disable lightbox editor UI for linked images]

* [WordPress/gutenberg#55269 Image: Stop crashing with Lightbox on image blocks without an image]

* [WordPress/gutenberg#55021 Update fullscreen icon]

* [WordPress/gutenberg#55217 Template Part block: Fall back to current theme if no theme attribute is given.] This change is part of fix for a performance regression re-introduced by [56818].

References:
* [WordPress/gutenberg#55298 Gutenberg PR 55298] Cherry-pick commits

Follow-up to [56818], [56816].

Props ellatrix, peterwilsoncc, jsnajdr, afercia, gziolo, isabel_brison, artemiosans, richtabor, bernhard-reiter, flixos90, mikachan, spacedmonkey, hellofromTonya.
See #59583, #59411.
Built from https://develop.svn.wordpress.org/trunk@56849


git-svn-id: https://core.svn.wordpress.org/trunk@56361 1a063a9b-81f0-0310-95a4-ce76da25c4cd
pento pushed a commit to WordPress/wordpress-develop that referenced this pull request Oct 12, 2023
Having the patterns registry inject the `theme` attribute into all Template Part blocks inside every pattern was found to negatively impact performance. It turns out that it's only required for the editor (i.e. in the REST API) but not on the frontend; there, it's instead possible to fall back to the currently active theme.

The latter change was made to the Pattern and Template Part blocks in WordPress/gutenberg#55217, which was sync'ed to Core in [56849]. Consequently, this changeset removes `theme` attribute insertion from the frontend.

Props flixos90, gziolo, dmsnell, hellofromtonya.
Fixes #59583.

git-svn-id: https://develop.svn.wordpress.org/trunk@56896 602fd350-edb4-49c9-b593-d223f7449a82
markjaquith pushed a commit to markjaquith/WordPress that referenced this pull request Oct 12, 2023
Having the patterns registry inject the `theme` attribute into all Template Part blocks inside every pattern was found to negatively impact performance. It turns out that it's only required for the editor (i.e. in the REST API) but not on the frontend; there, it's instead possible to fall back to the currently active theme.

The latter change was made to the Pattern and Template Part blocks in WordPress/gutenberg#55217, which was sync'ed to Core in [56849]. Consequently, this changeset removes `theme` attribute insertion from the frontend.

Props flixos90, gziolo, dmsnell, hellofromtonya.
Fixes #59583.
Built from https://develop.svn.wordpress.org/trunk@56896


git-svn-id: http://core.svn.wordpress.org/trunk@56407 1a063a9b-81f0-0310-95a4-ce76da25c4cd
github-actions bot pushed a commit to platformsh/wordpress-performance that referenced this pull request Oct 12, 2023
Having the patterns registry inject the `theme` attribute into all Template Part blocks inside every pattern was found to negatively impact performance. It turns out that it's only required for the editor (i.e. in the REST API) but not on the frontend; there, it's instead possible to fall back to the currently active theme.

The latter change was made to the Pattern and Template Part blocks in WordPress/gutenberg#55217, which was sync'ed to Core in [56849]. Consequently, this changeset removes `theme` attribute insertion from the frontend.

Props flixos90, gziolo, dmsnell, hellofromtonya.
Fixes #59583.
Built from https://develop.svn.wordpress.org/trunk@56896


git-svn-id: https://core.svn.wordpress.org/trunk@56407 1a063a9b-81f0-0310-95a4-ce76da25c4cd
@ockham ockham mentioned this pull request Oct 15, 2023
16 tasks
aaronjorbin pushed a commit to luminuu/wordpress-develop that referenced this pull request Oct 17, 2023
Updates the npm packages and code for:

* [WordPress/gutenberg#55121 List: fix forward merging of nested list]

* [WordPress/gutenberg#55182 Update consent string for using private APIs.]

* [WordPress/gutenberg#55204 useBlockSettings: add missing useMemo dependencies]

* [WordPress/gutenberg#55120 Remove the lightbox filter and view file when the lightbox setting is disabled.]

* [WordPress/gutenberg#55245 Patterns: Remove the version enforcement for npm in engines field]

* [WordPress/gutenberg#55237 Remove `@return void` from PHP function docs]

* [WordPress/gutenberg#55141 Image: Disable lightbox editor UI for linked images]

* [WordPress/gutenberg#55269 Image: Stop crashing with Lightbox on image blocks without an image]

* [WordPress/gutenberg#55021 Update fullscreen icon]

* [WordPress/gutenberg#55217 Template Part block: Fall back to current theme if no theme attribute is given.] This change is part of fix for a performance regression re-introduced by [56818].

References:
* [WordPress/gutenberg#55298 Gutenberg PR 55298] Cherry-pick commits

Follow-up to [56818], [56816].

Props ellatrix, peterwilsoncc, jsnajdr, afercia, gziolo, isabel_brison, artemiosans, richtabor, bernhard-reiter, flixos90, mikachan, spacedmonkey, hellofromTonya.
See #59583, #59411.

git-svn-id: https://develop.svn.wordpress.org/trunk@56849 602fd350-edb4-49c9-b593-d223f7449a82
aaronjorbin pushed a commit to luminuu/wordpress-develop that referenced this pull request Oct 17, 2023
Having the patterns registry inject the `theme` attribute into all Template Part blocks inside every pattern was found to negatively impact performance. It turns out that it's only required for the editor (i.e. in the REST API) but not on the frontend; there, it's instead possible to fall back to the currently active theme.

The latter change was made to the Pattern and Template Part blocks in WordPress/gutenberg#55217, which was sync'ed to Core in [56849]. Consequently, this changeset removes `theme` attribute insertion from the frontend.

Props flixos90, gziolo, dmsnell, hellofromtonya.
Fixes #59583.

git-svn-id: https://develop.svn.wordpress.org/trunk@56896 602fd350-edb4-49c9-b593-d223f7449a82
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Template Part Affects the Template Parts Block [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants