pattern-directory icon indicating copy to clipboard operation
pattern-directory copied to clipboard

Block theme: Dynamic pattern includes broken with GB 18.1

Open ryelle opened this issue 10 months ago • 1 comments

In the new Pattern Directory theme, there is code to swap out a pattern based on the current page context. For example, viewing a single pattern uses the single.html template, which contains <!-- wp:pattern {"slug":"wporg-pattern-directory-2024/single-pattern"} /-->. We use patterns like template parts so that we can use PHP i18n functions.

In a render_block_data hook, there's a check for pattern ownership, and if the current user owns the pattern, we swap out the slug to show the wporg-pattern-directory-2024/single-my-pattern pattern. This is also done for showing logged out messaging on the "my patterns" and "favorites" pages.

https://github.com/WordPress/pattern-directory/blob/1ced0d94b4d70d63a54a868f0b654b8a07b3a884/public_html/wp-content/themes/wporg-pattern-directory-2024/inc/block-config.php#L524-L558

What's the problem?

In Gutenberg 18.1, some code was added to replace the patterns earlier https://github.com/WordPress/gutenberg/pull/60349. This seems to not run render_block_data anymore, so the pattern conditional never kicks in. This means users don't see the correct actions on a pattern they own.

~Currently wp.org is pinned to 17.8.1 (though I'm going to try updating it to 18.0 on monday), so this won't affect us immediately.~ GB was unpinned, so this does impact us now.

More details

We do something similar in the Developer theme, but with the template-part block, so that should continue to work.

An alternate solution could be to add a new template into the hierarchy for logged in, but the current pattern-swap approach lets us update discrete content, rather than duplicating entire templates.

ryelle avatar Apr 12 '24 15:04 ryelle

I've updated w.org to pin Gutenberg to 18.0.1 while we figure out if this will be fixed in Gutenberg or if we need a new include workaround.

ryelle avatar Apr 17 '24 14:04 ryelle