Skip to content

Only output sourceURL if SCRIPT_DEBUG enabled.#10984

Closed
peterwilsoncc wants to merge 1 commit intoWordPress:trunkfrom
peterwilsoncc:fix/64369-only-show-sourceurl-for-script-debug
Closed

Only output sourceURL if SCRIPT_DEBUG enabled.#10984
peterwilsoncc wants to merge 1 commit intoWordPress:trunkfrom
peterwilsoncc:fix/64369-only-show-sourceurl-for-script-debug

Conversation

@peterwilsoncc
Copy link
Copy Markdown
Contributor

@peterwilsoncc peterwilsoncc commented Feb 20, 2026

Modifies the sourceURL output so it's only done if the SCRIPT_DEBUG constant is set to true.

Trac ticket: https://core.trac.wordpress.org/ticket/64369

Testing notes

  1. Add define( 'SCRIPT_DEBUG', false ); to your wp-config file
  2. Generate some content with various block types
  3. Activate a classic theme
  4. Ensure the hoisted styles block do not include the sourceurl
  5. Activate a block theme
  6. Ensure the block styles do not include the sourceurl
  7. Update the defintion above to define( 'SCRIPT_DEBUG', true );
  8. Reload the page
  9. Ensure the block styles do include the sourceurl
  10. Reactivate the classic theme
  11. Ensure the hoisted block styles do include the sourceurl

Use of AI Tools

Copilot helped with auto-complete/type ahead.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions
Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@peterwilsoncc peterwilsoncc marked this pull request as ready for review February 20, 2026 03:03
@peterwilsoncc peterwilsoncc requested review from sirreal and westonruter and removed request for sirreal February 20, 2026 03:03
@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 20, 2026

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @markkap.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

Core Committers: Use this line as a base for the props when committing in SVN:

Props peterwilsoncc, westonruter, jonsurrell.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@markkap
Copy link
Copy Markdown

markkap commented Feb 20, 2026

this sounds less than optimal as it seems to lead to the next workflow

  • There is a JS error. It is hard to trace where it comes from
  • change your wp config, set debug_scripts to true
  • recreate the error to be able to pinpoint where it comes from
  • solve the bug
  • change your wp config, remove debug_scripts setting

I would go for something less conditional like show it only to admins (I am assuming all developers have or can safely be given admin role, not sure how much this assumption is true in real life)

@markkap
Copy link
Copy Markdown

markkap commented Feb 21, 2026

on a second thought maybe it does not worth the effort at all as it adds relatively so little to the generated HTML, but if this kind of filtering must be done, maybe its better to use the enviroment setting as a signal.

function twentyfifteen_javascript_detection() {
$js = "(function(html){html.className = html.className.replace(/\bno-js\b/,'js')})(document.documentElement);";
$js .= "\n//# sourceURL=" . rawurlencode( __FUNCTION__ );
$js .= SCRIPT_DEBUG ? "\n//# sourceURL=" . rawurlencode( __FUNCTION__ ) : '';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of referencing SCRIPT_DEBUG repeatedly, what if there was instead a helper function like wp_should_print_inline_source_url()? This function could apply a filter which would have a default value set to SCRIPT_DEBUG. In this way, a site could opt-in to having sourceURL but not have to also serve unminified scripts and styles.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@westonruter How's this for a signature:

wp_should_print_inline_source_url( string $source, bool $echo = false ) : string

If not printing/returning the source URL the return value can be an empty string.

Random notes/thoughts:

  1. Bundled themes will require the function be polyfilled.
  2. Should there be a wp_scripts_ and wp_styles function to allow devs to target specific asset types?
  3. What is the internal escaping logic, or should that be the responsibility of the calling function?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about wp_should_print_inline_source_url(): bool? I think it could be a drop-in replacement for SCRIPT_DEBUG as you have in your PR here. Themes could continue to use SCRIPT_DEBUG if the function doesn't exist.

@sirreal
Copy link
Copy Markdown
Member

sirreal commented Feb 24, 2026

I think this can be closed based on further discussion in the ticket. There are no clear problems with the sourceURL comments.

@peterwilsoncc peterwilsoncc deleted the fix/64369-only-show-sourceurl-for-script-debug branch February 25, 2026 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants