Skip to content

Improve handling of delayed strategies when dependency aliases (bundles) are involved#80

Merged
westonruter merged 12 commits intofeature/enhance-wp-scripts-api-with-a-loading-strategyfrom
update/delayed-dependency-bundle-handling-redux
Jun 16, 2023
Merged

Improve handling of delayed strategies when dependency aliases (bundles) are involved#80
westonruter merged 12 commits intofeature/enhance-wp-scripts-api-with-a-loading-strategyfrom
update/delayed-dependency-bundle-handling-redux

Conversation

@westonruter
Copy link
Copy Markdown
Collaborator

@westonruter westonruter commented Jun 16, 2023

Fixes #76

Also addresses WordPress#4391 (comment)

Amends WordPress#4391

if ( $this->registered[ $dep ]->src ) {
$flattened[] = $dep;
} elseif ( $this->registered[ $dep ]->deps ) {
array_push( $flattened, ...$this->get_unaliased_deps( $this->registered[ $dep ]->deps ) );
Copy link
Copy Markdown
Collaborator Author

@westonruter westonruter Jun 16, 2023

Choose a reason for hiding this comment

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

Makes me so happy that the ... operator is supported in PHP 5.6+.

Copy link
Copy Markdown

@10upsimon 10upsimon Jun 16, 2023

Choose a reason for hiding this comment

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

Ya, this is great. Worth noting - for reference sake - that implementation of the spread operator differs from 5.6 - 7.x in the sense that 5.6 only supports argument unpacking, but not within array expressions. Thankfully, that is all that's needed here :)

@westonruter westonruter added the Script Loading Strategy Issues relating to the Script Loading Strategy (WPP) label Jun 16, 2023
@westonruter westonruter requested a review from felixarntz June 16, 2023 18:17
Copy link
Copy Markdown
Collaborator

@joemcgill joemcgill left a comment

Choose a reason for hiding this comment

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

This looks good, but I'm seeing one of the test cases fail when I run them locally:

Tests_Dependencies_Scripts::test_various_strategy_dependency_chains with data set "async-alias-members-with-defer-dependency" is failing, due to the expectation that the delayed inline script loader script will be included in the expected markup, but it is not.

@westonruter
Copy link
Copy Markdown
Collaborator Author

westonruter commented Jun 16, 2023

@joemcgill thanks for that. Strange I didn't notice before. On it...

This commit broke it: 4af0d23

@westonruter
Copy link
Copy Markdown
Collaborator Author

westonruter commented Jun 16, 2023

@joemcgill Fixed in 9cb97ab!

I blame myself for copy-pasting from the nested-aliases test case.

Copy link
Copy Markdown
Collaborator

@joemcgill joemcgill left a comment

Choose a reason for hiding this comment

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

Oh, the test was wrong and the delayed inline script loader really shouldn't have been printed. Neat!

@westonruter westonruter merged commit 5a14464 into feature/enhance-wp-scripts-api-with-a-loading-strategy Jun 16, 2023
@westonruter westonruter deleted the update/delayed-dependency-bundle-handling-redux branch June 16, 2023 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Script Loading Strategy Issues relating to the Script Loading Strategy (WPP)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants