fix: find synced patterns at any depth when registering block assets - #2987
Open
johansolve wants to merge 1 commit into
Open
fix: find synced patterns at any depth when registering block assets#2987johansolve wants to merge 1 commit into
johansolve wants to merge 1 commit into
Conversation
The scan for reusable blocks only looked at the top level of the parsed block tree, so a synced pattern nested inside another block was never found and the blocks it holds got none of their assets registered. For the Form block that also means no frontend script, so the form cannot be submitted. Walk the whole tree instead, collecting each pattern ID once.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2984.
Summary
Registration::enqueue_dependencies()scanned for reusable blocks (core/block) by filtering the flat list returned byparse_blocks(), so only patterns sitting at the top level of the content were found. A synced pattern nested inside a Group — the usual way people place one — was never seen, and none of the blocks it holds got their assets registered.Because the handles are registered conditionally, core's own render-time enqueue then no-ops on an unregistered handle, so the block ends up with neither its stylesheet nor its script. For the Form block that is not just cosmetic: submission happens in JS, so the form cannot be submitted at all.
The collection step now walks the whole tree, gathering each pattern ID once. Extracted as
Registration::get_reusable_block_ids(), public static like the neighbouringget_active_widgets_content(), so the behaviour is unit-testable without a builtbuild/directory.Since patterns can contain patterns,
enqueue_dependencies()still recurses per ID as before — this only changes which IDs it is handed.Test instructions
otter-form-styleandbuild/blocks/form.jsare both absent,.otter-form__containerfalls back todisplay: block, and submitting does nothing. After: both load and the form submits.Unit tests cover a pattern nested in a Group, patterns collected from several levels without duplicates, and content with no usable pattern (including a
core/blockwithout aref).I could not run the PHPUnit suite locally — it needs wp-env, and Docker was unavailable on this machine — so the new tests have not been executed.
composer run lint(phpcs) passes on both changed files, and phpstan reports the same 22 pre-existing errors inclass-registration.phpbefore and after, so nothing new was introduced. The behaviour itself is verified in a real WordPress 7.0.4 install: two otherwise identical pages against the same pattern, nested versus top level, before and after the patch.Checklist before the final review
Notes on the checklist: no attributes, markup or visual elements change, so the deprecation and copy/paste items do not apply. Assets are still only registered for blocks the page actually uses — the change is which patterns get scanned, not how much is loaded. The widgets path (
enqueue_dependencies( 'widgets' )) goes through the same collection step and is fixed along with it.Created with help of Claude Code.