With 'Aggregate JavaScript files' option turned on on performance page, JS files are not being aggregated. They are printed as if it was disabled.

I believe this bug was introduced by #2368797: Optimize ajaxPageState to keep Drupal 8 sites fast on high-latency networks, prevent CSS/JS aggregation from taking down sites and use HTTP GET for AJAX requests:

  • I went back in git history to the commit before that one (a8cccfc), reinstalled, and js aggregation takes place fine.
  • I then checked out the commit where this got in (dd3a597), reinstalled Drupal, and js aggregation no longer takes place.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Wim Leers’s picture

Assigned: Unassigned » Wim Leers
Issue tags: +Needs tests

I will investigate this first chance I get, probably 07:00 CET in 2 days. If confirmed, this implies we have no integration test coverage for JS aggregation!

willzyx’s picture

asset.js.collection_optimizer service is not called at all in AssetResolver::getJsAssets .. or am i missing something?

willzyx’s picture

Status: Active » Needs review
Manuel Garcia’s picture

Just applied the patch #2, seems to do the trick.

willzyx’s picture

I did some tests and patch at #2 seems to causes some issues with js settings (eg Block layout > Place blocks no longer works because of this). New patch attached

Status: Needs review » Needs work

The last submitted patch, 5: d8-aggregate-js-2413587-5.patch, failed testing.

willzyx’s picture

Status: Needs work » Needs review
FileSize
813 bytes

Rerolled

webchick’s picture

Priority: Major » Critical

This feels like a critical regression; I can't see us shipping with this setting being broken.

Wim Leers’s picture

Assigned: Wim Leers » Unassigned
Issue tags: -Needs tests
FileSize
1.29 KB
2.15 KB
2.73 KB

Confirmed, also confirmed that #7 fixes it. Slightly improving #7, and adding tests.

The last submitted patch, 9: d8-aggregate-js-2413587-9-test_only.patch, failed testing.

Gábor Hojtsy’s picture

Status: Needs review » Needs work
+++ b/core/modules/system/src/Tests/Common/AttachedAssetsTest.php
@@ -169,6 +169,21 @@ function testAggregatedAttributes() {
+    $this->assertEqual(2, count(\Drupal::service('asset.js.collection_renderer')->render($footer_js)), 'There are 2 JavaScript assets in the footer: one with drupalSettings, one with the sole aggregated JavaScript asset.');

The assert message explains things that are not actually asserted. Either assert those too or give a shorter explanation. I see the test ensures that there are not more things appearing in the footer, which is the point of the test.

Wim Leers’s picture

Status: Needs work » Needs review
FileSize
2.38 KB
1.38 KB
Gábor Hojtsy’s picture

Status: Needs review » Needs work

The last assert message is still saying things it does not assert. I mean it may pass even if the prior ones fail yet its pass message includes conditions that are tested on the prior one.

Wim Leers’s picture

Status: Needs work » Needs review
FileSize
2.37 KB
1.52 KB

Perhaps like this then? :)

Gábor Hojtsy’s picture

Status: Needs review » Reviewed & tested by the community

Looks good now :)

willzyx’s picture

Status: Reviewed & tested by the community » Needs work

patch at #14 causes the same issues described at #5

I did some tests and patch at #2 seems to causes some issues with js settings (eg Block layout > Place blocks no longer works because of this).

Wim Leers’s picture

#16: confirmed.

Wim Leers’s picture

Status: Needs work » Needs review
FileSize
2.5 KB
1.34 KB

Aha, I see, you fixed this in #5, that wasn't clear to me because there were no interdiffs.

Applied the same fix as in #5. It's a sensible change, because it doesn't make sense to "aggregate settings"; there is only ever going to be one piece of settings.

This is now identical to #7, with the sole addition of tests.

Wim Leers’s picture

(Note: I suspected #16 was caused by #784626: Default all JS to the footer, allow asset libraries to force their JS to the header, but it wasn't; the problem was that some AJAX responses would not generate a Settings command.)

Gábor Hojtsy’s picture

Status: Needs review » Reviewed & tested by the community

Looks good. Its redoing the fix in #5. I also tested it manually on the blocks admin page.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Given that this patch twice broke block admin by optimising settings it feels like we should be adding tests somewhere.

Wim Leers’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
4.29 KB
4.17 KB
1.84 KB

After first dismissing that as being not worth the time to write a test for because it'd be too tricky; I figured out a way that's not too tricky. The patch now includes a regression test to protect against the regression introduced in #2 and #14.

Status: Needs review » Needs work

The last submitted patch, 22: d8-aggregate-js-2413587-22_with_bug_of_2_and_14_FAIL.patch, failed testing.

Wim Leers’s picture

Status: Needs work » Needs review
FileSize
4.29 KB

GAHHH, wtf is going on with testbot? Again it didn't test a patch :/

opdavies’s picture

I've kicked that bot and restarted the tests, and it's returned as passed.

Gábor Hojtsy’s picture

Status: Needs review » Reviewed & tested by the community

@alexpott had a great point there. The regression test looks good to me, thanks!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Thanks @Wim Leers - nice test.

This issue addresses a critical bug and is allowed per https://www.drupal.org/core/beta-changes. Committed 65edcac and pushed to 8.0.x. Thanks!

  • alexpott committed 65edcac on 8.0.x
    Issue #2413587 by Wim Leers, willzyx: Aggregate JavaScript files no...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.