#54806 closed defect (bug) (fixed)
Site Editor: Remote block patterns are not loaded
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 5.9 | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Editor | Keywords: | has-patch has-test-info commit dev-reviewed |
| Focuses: | Cc: |
Description
Originally reported in https://github.com/WordPress/gutenberg/issues/37814.
- Activate an "empty" theme, e.g. the one that's in the Gutenberg repo. https://github.com/WordPress/gutenberg/tree/trunk/test/emptytheme
- Open the Site Editor.
- Open the inserter.
- Select "Patterns".
- Note that many block pattern categories are missing. (They appear in the post editor.)
The problem is that remote patterns are loaded when the current_screen hook is called.
Before proceeding, this hook checks that $current_screen→is_block_editor is true.
But is_block_editor is not set to true until after the current_screen hook is called.
The inserter hides the categories as they are empty.
Unfortunately there is no suitable hook that fires in between the call to $current_screen→is_block_editor( true ) and the call to WP_Block_Patterns_Registry::get_instance()->get_all_registered().
Perhaps we should call _load_remote_block_patterns and _load_remote_featured_patterns directly instead of using a hook? What do you think @hellofromtonya?
Attachments (1)
Change History (21)
This ticket was mentioned in PR #2178 on WordPress/wordpress-develop by noisysocks.
4 years ago
#1
- Keywords has-patch added
#2
@
4 years ago
Related #46195
The previous fix was to add some logic to WP_Screen to improve the accuracy of block editor detection, see d575d70fe.
I'm in two minds about the proposed patch in the linked pull request as I worry it could lead to blocking HTTP requests during page load when patterns are not needed.
I'll dig in to the code further and see if my concern is valid.
#3
@
4 years ago
I'm in two minds about the proposed patch in the linked pull request as I worry it could lead to blocking HTTP requests during page load when patterns are not needed.
Which screens don't need to load patterns? In my patch, I explicitly load them in the site editor (site-editor.php) and block editor (edit-form-blocks.php) which are the two places they're needed. I'm not loading them in the widgets block editor (widgets-form-blocks.php) as we don't support patterns there yet. There are no other calls to →is_block_editor( true ).
#4
@
4 years ago
I'm thinking about _load_remote_block_patterns() being called at an unexpectedly and relying on the is_block_editor check exists to prevent the request if it's not needed. For example, custom pages that use the block editor.
As it is, I don't think it's a problem, I just wanted to hold things up so I could check the plugin repo (it's dandy) and order of operations on a few things.
#5
follow-up:
↓ 6
@
4 years ago
I could keep the if ( ! $current_screen->is_block_editor ) check in _load_remote_block_patterns for backwards compatibly if we want. Just in case anybody is using it as it's not marked private.
#6
in reply to:
↑ 5
@
4 years ago
Replying to noisysocks:
I could keep the
if ( ! $current_screen->is_block_editor )check in_load_remote_block_patternsfor backwards compatibly if we want. Just in case anybody is using it as it's not marked private.
Yeah, let's keep it there to avoid the minor break in back-compatibility.
#8
@
4 years ago
- Keywords has-testing-info added
Test Report
Env:
- Theme: empty theme
- Plugins: none
- WordPress: trunk
- Localhost: wp-env
- Browsers: Firefox, Chrome, Edge, Safari
- OS: macOS Big Sur
Steps
Theme:
- Download files from Gutenberg repo
- Activate the empty theme
To test:
- Go to Posts > All Posts and edit "Hello world!" post
- Toggle open the inserter (click on the
+icon next to the WordPress logo) - Click on the Patterns tab. Expected behavior: patterns are loaded into the UI and dropdown is populated for exploring
- Go to Appearance > Editor (beta)
- Repeat steps 2 and 3. Expected behavior: patterns are loaded into the UI and dropdown is populated for exploring
Test Results
- Without the PR
- Patterns available in the block editor
- Patterns not available in site editor (able to reproduce the reported issue ✅)
- With the PR applied:
- Patterns available in the block editor
- Patterns available in site editor (resolves reported issue ✅)
#9
@
4 years ago
- Keywords commit added
Capturing comments from my review of the PR:
- The changes apply to only the block editor and site editor screens 👍
- Function signature deprecation is consistent with other instances in Core 👍
- Backwards compatibility functionality in
_load_remote_block_patterns()is retained 👍 - In testing, this PR resolves the reported issue (see the test report) while not impacting the block editor 👍
The solution works around the current_screen limitations to directly trigger remote pattern loading when on block or site editor screens. Should not impact other UIs/screens. I think this makes sense.
LGTM 👍 Marking for commit.
What do you think @peterwilsoncc?
#10
@
4 years ago
- Keywords dev-reviewed added
I tested the proposed PR and it fixes the issue: patterns are available in both the block and site editors.
This ticket was mentioned in Slack in #core by audrasjb. View the logs.
4 years ago
#12
@
4 years ago
Thanks @noisysocks, with the latest push the linked pull request looks commit ready to me.
Thanks for the gif and testing notes @hellofromTonya
#13
@
4 years ago
- Owner set to hellofromTonya
- Status changed from new to reviewing
Cool. Thanks @audrasjb and @peterwilsoncc for testing and reviewing. Let's it committed and backported w00t
Self-assigning for commit.
hellofromtonya commented on PR #2178:
4 years ago
#15
Committed via https://core.trac.wordpress.org/changeset/52593.
#16
@
4 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
Reopening to backport [52593] to 5.9. Thank you @audrasjb for the 2nd committer review!
#18
@
4 years ago
Alrighty, this has been committed to trunk and backported to 5.9 branch. Thank you everyone for your contributions and to @poena for reporting it.
Load any remote block patterns from w.org explicitly instead of using the
current_screenfilter. Thecurrent_screenfilter is unreliable as, in many cases e.g. the Site Editor,$current_scren->is_block_editoris not set until after the filter is executed.Trac ticket: https://core.trac.wordpress.org/ticket/54806