Fix inline scripts breaking when using jQuery on empty source scripts#74
Open
Fix inline scripts breaking when using jQuery on empty source scripts#74
Conversation
rebeccahum
requested changes
Oct 16, 2023
rebeccahum
reviewed
Oct 16, 2023
Committing changes from Rebecca's suggestion: https://github.com/Automattic/nginx-http-concat/pull/74/files/f2a2ceab92dcbb31e61542d07531582d32ec2eb1 Co-authored-by: Rebecca Hum <rebeccahum@gmail.com>
|
Tagging @WPprodigy for a second set of eyes. |
|
I don't really love solving this just for when |
|
Is it possible to get the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Expected/Desired Behavior
Scripts registered/enqueued without a source should add inline scripts after jQuery has been loaded.
Actual Behavior
Registering a dummy script without a
srcand using wp_add_inline_script() adds to DOM before jQuery is loaded.For example, the plugin PublishPress Capabilities registers a dummy script to attach an inline script using jQuery: https://github.com/publishpress/PublishPress-Capabilities/blob/06000a5be5f896e0f3cdcbe3990afe9310243e90/includes/functions-admin.php#L266-L271
The current logic processes empty src scripts before jQuery is defined. This PR adds an extra check within the first group definition to not process scripts that contain inline content, which is also later checked at line 113:
nginx-http-concat/jsconcat.php
Lines 113 to 115 in 73dbe08
Steps to Reproduce
Add this code to your theme to register a dummy script with an inline jQuery script:
Load a page on the frontend and check browser dev tools to find the
jQuery is not definederror.