Yoast / wordpress-seo

Yoast SEO for WordPress
https://yoast.com/wordpress/plugins/seo/
Other
1.78k stars 895 forks source link

WordPress SEO Premium - missing unminified assets #20129

Closed nlemoine closed 5 months ago

nlemoine commented 1 year ago

Please give us a description of what happened

I'm using WordPress SEO Premium. On my local dev environnement, with development mode "on", YOAST_ENVIRONMENT is set to development which loads the unminified version of assets (js, css, etc.).

The problem is that WordPress SEO Premium doesn't include unminified version of assets and it results in 404 and buggy admin features.

This happens because in Yoast SEO Premium, loading assets uses the WPSEO_CSSJS_SUFFIX constant defined here :

'filename'     => 'yoast-premium-social-metadata-previews-' . $version . WPSEO_CSSJS_SUFFIX . '.js',

You should take a decision here:

To Reproduce

Step-by-step reproduction instructions

  1. Define YOAST_ENVIRONMENT to development in your wp-config.php file
  2. Edit a post
  3. Open your browser console and check for 404 on assets

Expected results

Assets loading.

Actual results

Assets not loaded and features missing.

Screenshots, screen recording, code snippet

Capture d’écran 2023-04-07 à 10 00 09

Technical info

Not relevant.

Used versions

Not relevant.

monbauza commented 1 year ago

Thanks for submitting a bug report, @nlemoine! We've tagged it accordingly so our developers can review it.

nlemoine commented 1 year ago

@monbauza Friendly bump :)

This issue is still there and it doesn't seem to hard to fix. Could you take care of it?

nlemoine commented 6 months ago

@monbauza or someone, could you please take care of this?

This is unnecessarily annoying 🙏

josevarghese commented 5 months ago

Hi @nlemoine

Our development hasn't yet started working on this. Our product team always assesses the severity of this problem in relation to other open bug reports and new features. Based on their assessment, the bug report will be given a priority level. Our developers work on the highest priority issues first. Unfortunately, this means we cannot give you an estimate of when they'll start working on your report.

If you have any further information that may affect the prioritization or help our development team solve this bug, please feel invited to reply to this email. As soon as our development team has a clear indication in which release this problem will be solved, we'll send you an email to inform you.

nlemoine commented 5 months ago

Thanks for you feedback @josevarghese

Our developers work on the highest priority issues first

I'm a developer and I'm fully aware of priority/severity. I also know that there will be always be higher priority issues and the lower ones can stay in the queue for ages 🙂 It's been more than a year since I posted this issue.

What's a bit frustrating is that this one can be resolved without much effort:

either remove WPSEO_CSSJS_SUFFIX from premium asset filename and not respecting the YOAST_ENVIRONMENT constant by loading the minified version, whatever YOAST_ENVIRONMENT value

provide the unminified version of your premium assets

I can understand that you might not want to disclose your unminified JS sources (although it can still be reverse engineered), just avoid to trigger errors that prevents other developers to work upon your product.

I may add a few arguments in favor of not that much low priority:

josevarghese commented 5 months ago

Hi @nlemoine

Thanks for replying. Can you please tell us which mode is defined within the WP_DEVELOPMENT_MODE constant? I tried to use the plugin mode on my lab site but could not replicate the issue.

It would be helpful for me if you could share the exact constants you have added to the wp-config.php file.

We look forward to hearing from you.

nlemoine commented 5 months ago

Thanks your reply @josevarghese.

The WP_DEVELOPMENT_MODE constant is set to development.

define('YOAST_ENVIRONMENT', 'development');

I also have some other debug constants defined but they are not relevant here:

define('WP_DEBUG', true);
define('SCRIPT_DEBUG', true);

As I expleined in my first comment, the WPSEO_CSSJS_SUFFIX constant is an empty string when YOAST_ENVIRONMENT is set to development.

https://github.com/Yoast/wordpress-seo/blob/33681101a31ca43070016ef65bdc76415f915a86/wp-seo-main.php#L120

So all the asset paths defined won't have any .min suffix, for example:

    [
        'name'         => 'yoast-seo-premium-draft-js-plugins',
        'path'         => 'assets/js/dist/',
        'filename'     => 'wp-seo-premium-draft-js-plugins-' . $version . WPSEO_CSSJS_SUFFIX . '.js',
        'in_footer'    => true,
        'dependencies' => [
            WPSEO_Admin_Asset_Manager::PREFIX . 'search-metadata-previews',
        ],
    ],

Will try to load the following URL: https://domain.com/wp-content/plugins/wordpress-seo-premium/assets/js/dist/wp-seo-premium-draft-js-plugins-2290.js

But this file isn't shipped: Capture d’écran 2024-06-19 à 22 08 43

Maybe your lab site includes the unminified versions of the premium assets? But the package (wordpress-seo-premium) I get (using composer) doesn't.

Check the network tab of your browser and filter JS files by name wordpress-seo-premium/assets/js/dist, you should only have 404 when YOAST_ENVIRONMENT is set to development.

josevarghese commented 5 months ago

Hi @nlemoine

Thanks for the details. Now, I can replicate it after setting the YOAST_ENVIRONMENT constant, where the JS scripts are showing a 404 error. One doubt, can you tell me the reason why you are defining the YOAST_ENVIRONMENTconstant on your local site, is it that to prevent the SEO Data Optimization?

nlemoine commented 5 months ago

One doubt, can you tell me the reason why you are defining the YOAST_ENVIRONMENT constant on your local site, is it that to prevent the SEO Data Optimization?

Yes, and pretty print JSON schemas. I know there are hooks to achieve this but the constant is a one line, no hook solution that can go to the dev env config file (e.g. at wp-config.php boot loading stage) I'm loading on development mode (which isn't possible using hooks).

josevarghese commented 5 months ago

Thanks for sharing the details @nlemoine

We discussed your use case with our development team internally and decided that we will not work on this any time soon as the YOAST_ENVIRONMENT constant is for other user cases for our team to debug while working and not intended for the use case you have mentioned.

As you are aware, we are providing the filters to disable both the SEO Data Optimization process and also to show the schema in the pretty print format in the source code. So we recommend you to use the filters for your case instead of using the YOAST_ENVIRONMENT constant.

The filter to enable the pretty print schema is mentioned over our developer portal at here. add_filter( 'yoast_seo_development_mode', '__return_true' );

To disable the indexing process, use the filter Yoast\WP\SEO\should_index_indexables filter as false as mentioned at here. `add_filter( 'Yoast\WP\SEO\should_index_indexables', '__return_false' );