Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#45535 closed defect (bug) (fixed)

Unminified react and react-dom

Reported by: emilushi's profile emilushi Owned by: ocean90's profile ocean90
Milestone: 5.0.3 Priority: normal
Severity: normal Version: 5.0
Component: Script Loader Keywords: has-patch
Focuses: javascript Cc:

Description

Even if you define SCRIPT_DEBUG to true React and React-Dom are loaded minified and based on my inspection that is caused $dev_suffix on line 79 of wp-includes/script-loader.php.

The wp_scripts_get_suffix() will always return .min if passed arguments is equal to dev. As seen on line 757 of wp-includes/script-loader.php the wp_scripts_get_suffix() is setting $develop_src to false if $wp_version doesn't contain string -src for which I don't know why $wp_version will have to contain that string.

I wanted to fix it but I din't understand this part: $develop_src = false !== strpos( $wp_version, '-src' ), why $develop_src is depended on $wp_version.

Personally I think it should be depended on SCRIPT_DEBUG constant.

Attachments (1)

45535.diff (875 bytes) - added by earnjam 6 years ago.

Download all attachments as: .zip

Change History (12)

#1 follow-up: @afercia
6 years ago

@emilushi that line of code is meant for the development trunk version, where the version is always identified with a -src suffix. For example:

$wp_version = '5.1-alpha-43677-src'

Instead, stable versions have just the version number:

$wp_version = '4.9.8';

This is intentional so that the trunk version always uses the non minified files.

#2 in reply to: ↑ 1 @emilushi
6 years ago

Thanks for the information.
I now understand it clear, then it means is needed to add another condition for cases when using stable release with SCRIPT_DEBUG to true

Replying to afercia:

@emilushi that line of code is meant for the development trunk version, where the version is always identified with a -src suffix. For example:

$wp_version = '5.1-alpha-43677-src'

Instead, stable versions have just the version number:

$wp_version = '4.9.8';

This is intentional so that the trunk version always uses the non minified files.

This ticket was mentioned in Slack in #core-js by earnjam. View the logs.


6 years ago

@earnjam
6 years ago

#4 @earnjam
6 years ago

  • Keywords needs-patch removed

So it's not clear to me what the determination is between when to use $suffix vs $dev_suffix on any given script, however in 45535.diff I simply switched to following the normal use of $suffix, which allows it to check SCRIPT_DEBUG value first and then falls back to checking for -src in the WP version.

This is particularly helpful when developing with React, which otherwise shows minified errors and requires you to click to visit reactjs.org for the full error messages.

I'm not sure why we don't just honor SCRIPT_DEBUG and then fall back to -src for all scripts. It appears this change was first introduced in [27170], but I couldn't find any discussion around why and it seems scripts included in core are split between the two suffix options to follow.

#5 @sanchothefat
6 years ago

I ran into this today as well. We should absolutely respect SCRIPT_DEBUG with this otherwise the developer experience of creating new blocks for the editor is horrible.

I've worked around it for now with this mu-plugin https://gist.github.com/roborourke/887ccc6a8070cb7dbd69b897bee6af7f

Would love to see this resolved in core!

#6 @Frank Klein
6 years ago

This should be fixed because:

  1. Core breaks with a convention established by the Gutenberg plugin, see lib/client-assets.php.
  2. Whether a script is minified or not doesn't change its functionality. But React has a production version and a development version, which differ a lot. And the production version does not have any debugging helpers in it, which makes block development in Core impossible.

This ticket was mentioned in Slack in #core-js by earnjam. View the logs.


6 years ago

#8 @ocean90
6 years ago

  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 5.0.3
  • Owner set to ocean90
  • Status changed from new to reviewing

#9 @ocean90
6 years ago

In 44391:

Script Loader: Load unminified package vendor scripts when SCRIPT_DEBUG is set.

The unminified package vendor scripts are bundled with the release package thus the value of the SCRIPT_DEBUG constant should be honored.

Props earnjam.
See #45535.

#10 @ocean90
6 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 44393:

Script Loader: Load unminified package vendor scripts when SCRIPT_DEBUG is set.

The unminified package vendor scripts are bundled with the release package thus the value of the SCRIPT_DEBUG constant should be honored.

Merge of [44391] to the 5.0 branch.

Props earnjam.
Fixes #45535.

This ticket was mentioned in Slack in #core-editor by earnjam. View the logs.


6 years ago

Note: See TracTickets for help on using tickets.