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

Patterns containing non-core blocks are losing styling in the Inserter with Gutenberg 13 #40562

Closed
WhiteHeatherClub opened this issue Apr 22, 2022 · 23 comments · Fixed by #40842
Assignees
Labels
[Block] Pattern Affects the Patterns Block Needs Testing Needs further testing to be confirmed. [Priority] High Used to indicate top priority items that need quick attention [Type] Bug An existing feature does not function as intended [Type] Regression Related to a regression in the latest release

Comments

@WhiteHeatherClub
Copy link

WhiteHeatherClub commented Apr 22, 2022

Patterns containing non-core blocks are losing styling moving from Gutenberg 12.9 to 13.0 in the Inserter - they are placed and display fine on the page Editor, it's the Inserter Previews that are affected.

This happens in either a classic theme (i.e. Twenty Twenty One) or FSE theme (Twenty Twenty Two)
gut13

Originally posted by @WhiteHeatherClub in #40305 (comment)

@WhiteHeatherClub WhiteHeatherClub changed the title Patterns containing non-core blocks are losing styling in Gutenberg 13 Patterns containing non-core blocks are losing styling in the Inserter with Gutenberg 13 Apr 22, 2022
@carolinan
Copy link
Contributor

carolinan commented Apr 24, 2022

Hi
Please include detailed information about the non-core blocks, such as the name of the block and plugin, so that we can try to reproduce the problem.

@WhiteHeatherClub
Copy link
Author

Hi, I'm using Getwid blocks - in my case patterns are made with the Media & Text Slider, Section and Image Slider (but I'm guessing it would affect the others as well).

Also on this post #40305 another Dev is mentioning it is happening with AinoBlocks as well.

@gziolo gziolo added [Block] Pattern Affects the Patterns Block Needs Testing Needs further testing to be confirmed. labels Apr 30, 2022
@ellenbauer
Copy link

ellenbauer commented May 4, 2022

I want to report the same issue, I loose all CSS styling of our AinoBlocks plugin (https://wordpress.org/plugins/aino-blocks/) blocks, as soon as I activate Gutenberg 13+, see screenshots below:

Gutenberg plugin 13.1.0 active with Aino Blocks and one of our premium themes, but you can use our Aino free theme (https://wordpress.org/themes/aino/) to replicate the issue as well:

Screen Shot 2022-05-04 at 9 54 18 AM

As a comparison without the Gutenberg plugin active:

Screen Shot 2022-05-04 at 9 54 47 AM

This is a major issue for us and I wonder how to solve it. Any kind of help or hint on what we can do to fix it would be greatly appreciated.

@ndiego ndiego added [Type] Bug An existing feature does not function as intended [Priority] High Used to indicate top priority items that need quick attention labels May 4, 2022
@ndiego
Copy link
Member

ndiego commented May 4, 2022

I have been able to confirm.

Testing steps:

  1. Ensure you are running 6.0 or Gutenberg 13+ is active
  2. Install and activate the Aino theme
  3. Install and activate Aino Blocks
  4. Navigate to a new page and preview patterns in the Pattern Explorer, they will appear broken
  5. Revert to 5.9.3 and disable Gutenberg
  6. Preview the patterns again, and they will appear correctly

cc @Mamaduka @ntsekouras I am guessing this is related to the new patterns REST API "stuff", but could use your expertise.

cc @annezazu @priethor @gziolo @adamziel pinging you all for review, this is a significant breaking change that we need to get fixed before the 6.0 release.

@ndiego
Copy link
Member

ndiego commented May 4, 2022

In investigating this more deeply, I do no believe this is related to the REST API patterns implementation. Block styles in the Aino Blocks plugin are enqueued in a single stylesheet with the enqueue_block_editor_assets hook. This was/is a very common implementation for adding custom styles in the Editor.

Something changed in 13.0+ and WordPress 6.0 where this is no longer working properly in Block Previews or the Site Editor. If you insert one of the Aino Patterns into a template in the Site Editor, they will also lack styles. See the screenshot below:

image

@Mamaduka
Copy link
Member

Mamaduka commented May 4, 2022

#40469 might be related to this issue. Unfortunately, I couldn't track down the source of the problem.

@ndiego
Copy link
Member

ndiego commented May 4, 2022

Thanks for pointing out #40469 @Mamaduka, I just tested that and confirmed that's also a major issue.

@getdave

This comment was marked as outdated.

@ndiego
Copy link
Member

ndiego commented May 4, 2022

@getdave yes, but they are not being loaded in the iframe where the pattern is rendering. This is true for the pattern previews as well as the Site Editor.

@ndiego ndiego added the [Type] Regression Related to a regression in the latest release label May 4, 2022
@gziolo
Copy link
Member

gziolo commented May 4, 2022

I guess it means that it's an issue with how styles/scripts are registered for 3rd party blocks that aren't compatible with the iframed version of the editor. Based on the report from @getdave, it's clear that styles are present on the page, so it must be something with passing them through to the iframe.

@ndiego
Copy link
Member

ndiego commented May 4, 2022

@gziolo could this code be related? #40278

@gziolo
Copy link
Member

gziolo commented May 4, 2022

Yes, it would be this logic but previous PR. The one you shared only moves code between files. One thing we struggled with before Beta 1 was the same logic missing in WP Core which caused missing styles in iframed editors. In effect, block styles for core blocks worked only in the post editor.

@Mamaduka
Copy link
Member

Mamaduka commented May 4, 2022

This is original PR that change asset resolving for iframed editors #37193.

@ndiego
Copy link
Member

ndiego commented May 4, 2022

@Mamaduka that is what it seems like, but the issue only starts occurring in 13.0+. That PR looks to have been included in 12.2

@getdave
Copy link
Contributor

getdave commented May 4, 2022

Looking into this a bit...

I have the following code in a test plugin active on my Gutenberg 13 enabled site:

function myplugin_enqueue_block_editor_assets() {

	wp_enqueue_style(
		'davesmith-editor-css',
		plugins_url( 'test-editor.css', __FILE__ ),
		array( 'wp-edit-blocks' )
	);

	wp_enqueue_block_style(
		'core/paragraph',
		array(
			'handle' => 'davesmith-block-css',
			'src'    => plugins_url( 'test-block.css', __FILE__ ),
			'deps'   => array( 'wp-edit-blocks' ),
		)
	);

}
add_action( 'enqueue_block_editor_assets', 'myplugin_enqueue_block_editor_assets' );

Both are seen in the network tab so it looks like I'm enqueuing them correctly:
Screen Shot 2022-05-04 at 15 41 10

...but when I debug packages/edit-site/src/components/block-editor/resizable-editor.js, I find that neither settings.__unstableResolvedAssets nor settings.styles contains a reference to those enqueued styles.

Similarly a call to wp.data.select( 'core/edit-site' ).getSettings() in the console of the Site Editor reveals that the styles property of the settings object also doesn't contain a reference to the enqueued styles.

Here is where the unsableResolvedAssets is prepared:

add_filter(
'block_editor_settings_all',
function( $settings ) {
// In the future we can allow WP Dependency handles to be passed.
$settings['__unstableResolvedAssets'] = gutenberg_resolve_assets();
return $settings;
}
);

...but gutenberg_resolve_assets doesn't appear to care about block styles that are registered outside of block.json.

function gutenberg_resolve_assets() {

@ndiego
Copy link
Member

ndiego commented May 4, 2022

Thanks for digging into this. I am becoming more and more convinced it is related to #37193. It did not popup until 13.0 with 5.9.3, even though it was merged in 12.2, because of a missing backport that was never done: WordPress/wordpress-develop#2564 (comment). This backport was fixed, which seem to have then made the issue appear. That is my best guess at the moment.

@gziolo
Copy link
Member

gziolo commented May 4, 2022

@getdave wp_enqueue_block_style was added to WP core 6 months ago with:
WordPress/wordpress-develop@f034bc8

I don't think it ever registered scripts/styles to the block type object in the registry.

@gziolo
Copy link
Member

gziolo commented May 4, 2022

Thanks for digging into this. I am becoming more and more convinced it is related to #37193. It did not popup until 13.0 with 5.9.3, even though it was merged in 12.2, because of a missing backport that was never done: WordPress/wordpress-develop#2564 (comment). This backport was fixed, which seem to have then made the issue appear. That is my best guess at the moment.

Here is the commit where we backported changes from Gutenberg 12.2 to WordPress core: WordPress/wordpress-develop@1d086c5. It resolved the issue with styles for core block in the iframed editors.

I'm still not sure how this could work correctly with WordPress 5.9.3 and Gutenberg 12.1 and earlier, because the old handler looks similar.

@ellenbauer
Copy link

Thank you so much for all your help and digging into the issue further. Please let me know if I should make any changes to adding the patterns for testing. I would love to be able to help further.

@getdave
Copy link
Contributor

getdave commented May 4, 2022

@getdave wp_enqueue_block_style was added to WP core 6 months ago with:
WordPress/wordpress-develop@f034bc8

Ah my mistake. I'm sure I saw one of the reports mentioned that being used. Looking an Aino Blocks Plugin they are just using wp_enqueue_style hooked on enqueue_block_editor_assets so I'll focus on that.

@ndiego
Copy link
Member

ndiego commented May 4, 2022

Last update for today. I have narrowed down the issue to something that changed in 13.0. The issue does occur in 6.0 Beta 1 without Gutenberg active. So some change happened between 12.9 -> 13.0 and 5.9.3 -> 6.0 that is causing this. I wish I could be more sure about the cause, but currently, everything is pointing to #37193. That said, that PR was merged in 12.2 and there are no styling issues with 12.2 and 5.9.3. The issues only begin at 13.0.

I will add more notes if I discover anything relevant, but more eyes are definitely welcomed. 🙏

@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label May 5, 2022
@gziolo
Copy link
Member

gziolo commented May 5, 2022

A potential fix is ready for testing: #40842.

@WhiteHeatherClub
Copy link
Author

Thank you for such great work with fixing this. First Class!

@priethor priethor removed the [Status] In Progress Tracking issues with work in progress label May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Pattern Affects the Patterns Block Needs Testing Needs further testing to be confirmed. [Priority] High Used to indicate top priority items that need quick attention [Type] Bug An existing feature does not function as intended [Type] Regression Related to a regression in the latest release
Projects
No open projects
Archived in project
Development

Successfully merging a pull request may close this issue.

9 participants