gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

dashicons Icons Not Displaying at Site Editor and Post Editor of v6.3

Open delhee opened this issue 3 years ago • 12 comments

Description

Dear WordPress Team,

First of all, really appreciate your efforts and contributions to make site building easier and more favorable. I have made myself a plugin developer. This time I am facing a problem regarding dashicons with the latest version of WordPress.

Here is the symptom. After upgrading WordPress to v6.3 at 18:16 (Asia Pacific Time) Aug 9th 2023, the dashicons icons I used at the site editor and post editor stopped displaying. But it does display in the front end and in anything of the previous versions. Later on, I have simulated the situation and realized that the dashicons.min.css style sheet is not loaded at the of the editor-canvas iframe (as shown in screenshots). When I loaded the dashicons css with inspector tool, the icon displayed again.

Please let me know, at your own convenience, if this a carefully thought-through decision or you will resolve it in your next release.

Thank you again for your work.

Step-by-step reproduction instructions

Expected Result: Need to add a dashicons icon with the following code:

<div style="width: 5rem;height: 5rem;background: cyan;">
    <span class="dashicons dashicons-admin-comments" style="font-size: 3rem;width: 3rem;color: #aaa;height: 3rem;"></span>
</div>
expected-result

Actual Result: The icon does not show up. Previous versions are normal. Front end is normal. actual-result

My Finding: Once I loaded the dashicons.min.css into the <head> of editor-canvas <iframe>, things are back to normal.
dashicons css-is-not-loaded-at-editor-canvas-iframe

Screenshots, screen recording, code snippet

No response

Environment info

No response

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

No

delhee avatar Aug 10 '23 13:08 delhee

Hi @delhee - thanks for the report. It would be good to help try and narrow down a potential cause of this by:

  • Testing with a default theme like TwentyTwentyThree active.
  • Testing with all plugins disabled except Gutenberg

I also wanted to check - are you adding that code into an HTML block in the editor?

jordesign avatar Aug 10 '23 23:08 jordesign

@t-hamano, do I remember correctly that you fixed a similar issue recently?

Mamaduka avatar Aug 11 '23 05:08 Mamaduka

Hi @jordesign, thanks for the feedback.

I was already using the unmodified twentytwentythree theme, when I took the abovementioned screenshots.

As requested, I have disabled all other plugins except for Gutenberg. The symptoms are the same: dashicons icon does not show up in the site editor of v6.3 and is normal in the v6.2. The HTML code mentioned above was inserted via browser’s inspector tool.

In case you need to know why I insert HTML through inspector tool, here is what is happening in my world. I’ve been developing a block type plugin that displays a search icon from dashicons collection. My work-in-progress plugin worked fine in the previous versions of site editors. But once the WordPress was upgraded to v6.3, the search icon disappeared from my site editor. I did some trouble shooting for a while and with the inspector tool, I put some random text in between the <span ...>test123</span>. The text shows up. Then I thought it was time to open a ticket under your github repo. I don’t think it’s a good idea to confuse your team with the messy complicated code of an unfinished plugin. So I figured out a piece of simple HTML code to describe the situation and inserted it with browser’s inspector tool. I tried out the same HTML in the same manner in the site editors of both v6.2 and v6.3. As a result, the former is normal and the latter is not.

Since that you have brought it up, I tried to insert the same piece of HTML code mentioned in this ticket via the Custom HTML Block. The dashicons icon cannot display either. If I put a text in between the <span ...>test567</span>, then the text shows up, as illustrated below. By the way, I also noticed that the <iframe> of the Custom HTML Block does not load the dashicons.min.css into the <head>.

WordPress v6.2 site editor, with the following code inserted via inspector tool and via Custom HTML block:

<div style="width: 5rem;height: 5rem;background: cyan;">
    <span class="dashicons dashicons-admin-comments" style="font-size: 3rem;width: 3rem;color: #aaa;height: 3rem;"></span>
</div>

wp6 2-dashicons-custom-html-issue

WordPress v6.3 site editor, with the same code inserted via inspector tool and via Custom HTML block:

wp6 3-dashicons-custom-html-issue

WordPress v6.3 site editor, with the following code inserted via Custom HTML block:

<div style="width: 5rem;height: 5rem;background: cyan;">
    <span class="dashicons dashicons-admin-comments" style="font-size: 3rem;width: 3rem;color: #aaa;height: 3rem;">test567</span>
</div>

wp6 3-dashicons-custom-html-issue-with-text-between-span-tags

Please let me know if you want any additional info.

delhee avatar Aug 11 '23 06:08 delhee

Thanks for pinging me. I have not worked on this issue, but I know that similar problems have been reported in the past:

  • #44205
  • #50897

In these issues, the results were dependent on the value of SCRIPT_DEBUG. Therefore I tested under different scenarios in WordPress 6.3. Here is the code I used for testing:

wp.blocks.registerBlockType( 'example/dashicon', {
	apiVersion: 3,
	title: 'dashicon',
	edit: () => wp.element.createElement( wp.components.Dashicon, { icon: 'admin-site' } ),
	save: () => null,
} )

The results were as follows:

  • Disable the latest Gutenberg plugin
    • SCRIPT_DEBUG is true
      • The editor is iframed: ❌ Reproduced
      • The editor is not iframed: ✅ Not reproduced
    • SCRIPT_DEBUG is false
      • The editor is iframed: ❌ Reproduced
      • The editor is not iframed: ✅ Not reproduced
  • Enable the latest Gutenberg plugin
    • SCRIPT_DEBUG is true
      • The editor is iframed: ✅ Not reproduced
      • The editor is not iframed: ✅ Not reproduced
    • SCRIPT_DEBUG is false
      • The editor is iframed: ✅ Not reproduced
      • The editor is not iframed: ✅ Not reproduced

The point is that regardless of the value of SCRIPT_DEBUG, if the editor is iframed, this problem is reproduced in the core. The Gutenberg plugin cannot reproduce this.

My guess is that it is because the Gutenberg plugin explicitly has dashicons as a dependency.

https://github.com/WordPress/gutenberg/blob/d5d8533cf2cc04bb005bda147114cf00782d6c38/lib/client-assets.php#L296

I can reproduce the problem by changing this argument to array() as a test.

So, Is the fundamental solution to add dashicon to the dependencies of any of the handles on the core side as well?

BTW, there is a #43725 that suggests deprecating the dashicon string in the Icon component. Therefore, regardless of when or if this issue is resolved, I recommend using the svg icons from the @wordpress/icons package instead.

t-hamano avatar Aug 11 '23 08:08 t-hamano

Ran into this issue while taking my theme more into the FSE direction and using API Version 3 on all of my custom blocks. I don't know what the underlying issue is but I was able to fix by enqueuing the dashicons CSS file.

add_action('enqueue_block_assets', function (): void {
    wp_enqueue_style('dashicons');
});

Edit: Possibly the Dashicons CSS file is not being enqueued into the block iframe wrapper?

rleecrewmp avatar Aug 25 '23 03:08 rleecrewmp

Seeing as this issue is still open, here are my comments.

  • I had the same problem with my oik-bbw/dashicons block.
  • My analysis indicates that the fix applied to Gutenberg has not been applied to WordPress core.
  • The question I'm left with is "Should the dependency of wp-components on dashicons be implemented in core or does anyone using dashicons in their custom code have to implement the identified workaround?"

bobbingwide avatar Oct 12 '24 12:10 bobbingwide

We just ran into this as well. It does appear that dashicons must be listed explicitly as a dependency.

As we are using a custom theme, we were able to fix by adding dashicons as a dependency to the styles we enqueue into the editor:

add_action(
	'enqueue_block_assets',
	function () {
			wp_enqueue_style(
				'mytheme_editor',
				get_template_directory_uri() . '/assets/editor.min.css',
				array( 'dashicons' ),
				'1.0.0',
			);
	}
);

smwoll avatar Mar 10 '25 15:03 smwoll

Bug Report

Description

Dashicons are not displayed in iframe based editors when the Gutenberg plugin is disabled.

Environment

  • WordPress: 6.8.2
  • PHP: 8.2.27
  • Server: nginx/1.26.1
  • Database: mysqli (Server: 8.0.35 / Client: mysqlnd 8.2.27)
  • Browser: Chrome 138.0.0.0
  • OS: macOS
  • Theme: Twenty Twenty-Three 1.6
  • MU Plugins: None activated
  • Plugins:
    • Gutenberg 21.2.0
    • Test Reports 1.2.0

Steps to Reproduce

  1. Register a custom block that renders a Dashicon. Example:
wp.blocks.registerBlockType( 'example/dashicon', {
	apiVersion: 3,
	title: 'dashicon',
	edit: () => wp.element.createElement( wp.components.Dashicon, { icon: 'admin-site' } ),
	save: () => wp.element.createElement( wp.components.Dashicon, { icon: 'admin-site' } ),
} )
  1. Visit the Site Editor or Post Editor and add the block
  2. ✅ The Dashicon renders correctly in both the editor and the frontend.
  3. Now disable the Gutenberg plugin.
  4. 🐞 The Dashicon no longer renders in the editor.

Expected Results

  1. ✅ Dashicons should render correctly in iframe based editors, regardless of whether the Gutenberg plugin is active.

Actual Results

  1. ❌ Dashicons do not render inside iframe based editors when the Gutenberg plugin is disabled.

Additional Notes

  • Result Matrix:
Setup Editor Frontend
Gutenberg Plugin Enabled ✅ Rendered ✅ Rendered
Gutenberg Plugin Disabled ❌ Doesn't render ✅ Rendered
  • Confirmed fix/workaround to render the Dashicons:
add_action( 'enqueue_block_assets', function () {
    wp_enqueue_style( 'dashicons' );
} );

BugReportOnWeb avatar Jul 28 '25 14:07 BugReportOnWeb

Reproduction Report

Description

❌ This report can't validate whether the issue can be reproduced.

Environment

  • WordPress: 6.9-alpha-60093-src
  • PHP: 8.2.29
  • Server: Apache/2.4.62 (Debian)
  • Database: mysqli (Server: 11.8.2-MariaDB-ubu2404 / Client: mysqlnd 8.2.29)
  • Browser: Chrome 138.0.0.0
  • OS: Windows 10/11
  • Theme: Twenty Twenty-One 2.6
  • MU Plugins: None activated
  • Plugins:
    • Gutenberg 21.3.0-rc.1
    • Test Reports 1.2.0

Testing Instructions

  1. Create a block that displays a Dashicon (code in supp artifats)
  2. Add this block in a post
  3. ❌ Dashicon is showing in the editor and the front end

Actual Results

  1. ❌ Error condition is not occurring

Additional Notes

  • I've tested following @BugReportOnWeb with latest Gutenberg 21.3-rc3 and dashicons are showing both in editor and in front
  • As @t-hamano commented it seems that the problem is with the iframed version of Core that is not happening with the plugin.
  • So basically here the decision is to consider closing this as wontfix and as suggested by him opting for @wordpress/icons instead of trying to use the dashicons striaghtly in the iframed versions of Core.
  • At the same time, since this is not happening in the plugin itself, I wonder if this belongs to a Core Trac issue (in case it could be worthy to be solved).

Supplemental Artifacts

Result Image

Code, I've used the one above, with a little tweak to also show the dash icon in the save condition (for the front end)

const dashicon = wp.element.createElement( wp.components.Dashicon, {
	icon: 'admin-site',
} );

registerBlockType( 'create-block/greater-than-sign', {
	title: __( 'Greater Than Sign', 'greater-than-sign' ),
	icon: 'smiley',
	category: 'widgets',
	edit: () => dashicon,
	save: () => dashicon,
} );

SirLouen avatar Jul 28 '25 21:07 SirLouen

Later on, I have simulated the situation and realized that the dashicons.min.css style sheet is not loaded at the of the editor-canvas iframe (as shown in screenshots). When I loaded the dashicons css with inspector tool, the icon displayed again.

Please let me know, at your own convenience, if this a carefully thought-through decision or you will resolve it in your next release.

I'm not sure if this was an intentional change or an unintentional bug, but fixing this issue in core is easy - just make the following change:

diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php
index 3beddac135..1112d795d3 100644
--- a/src/wp-includes/script-loader.php
+++ b/src/wp-includes/script-loader.php
@@ -1700,6 +1700,7 @@ function wp_default_styles( $styles ) {
 
        // Only add CONTENT styles here that should be enqueued in the iframe!
        $wp_edit_blocks_dependencies = array(
+               'dashicons',
                'wp-components',
                /*
                 * This needs to be added before the block library styles,

However, there are some things to consider:

@WordPress/gutenberg-components We are debating whether to enqueue a CSS file for Dashicons into the editor iframe. If you have any thoughts, please let us know.

Personally, I prefer to prioritize editor performance and not add Dashicons. Users who really need them, there is a workaround available to enqueue it.

t-hamano avatar Jul 29 '25 06:07 t-hamano

@t-hamano technically if #70743 moves forward, then this will be failing for all versions of GB from that point, right?

For me, this is a clear wontfix hands down for all the reasons you state

Loading a CSS file in the frontend by default, that is barely going to be used by most, is not acceptable: Image

And it's even worse, as you say, when there is an SVG version.

I would 100% rather opt if anyone wants to use it, load it on demand like you suggest

SirLouen avatar Jul 29 '25 11:07 SirLouen

technically if https://github.com/WordPress/gutenberg/issues/70743 moves forward, then this will be failing for all versions of GB from that point, right?

If you're talking about the core, then yes.

If the GB plugin is enabled, the problem does not occur, as per the comment below:

The point is that regardless of the value of SCRIPT_DEBUG, if the editor is iframed, this problem is reproduced in the core. The Gutenberg plugin cannot reproduce this.

My guess is that it is because the Gutenberg plugin explicitly has dashicons as a dependency.

https://github.com/WordPress/gutenberg/blob/d5d8533cf2cc04bb005bda147114cf00782d6c38/lib/client-assets.php#L296

I can reproduce the problem by changing this argument to array() as a test.

For me, this is a clear wontfix hands down for all the reasons you state

Well, let's close this issue.

Loading a CSS file in the frontend by default, that is barely going to be used by most, is not acceptable:

To be clear, the scope of this issue is the block editor, and this issue is not related to the frontend. On the frontend, the Dashicon CSS is loaded if the user is logged in, because the admin bar uses Dashicons. For non-logged-in users, the dash icon CSS is not loaded, which is the intended behavior.

So developers who need Dashicons CSS only in the iframe editor add a conditional statement inside the hook:

add_action( 'enqueue_block_assets', function () {
  if ( is_admin() ) {
    wp_enqueue_style( 'dashicons' );
  }
} );

t-hamano avatar Jul 30 '25 13:07 t-hamano