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.

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

StatusFileSize
new661 bytes

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

StatusFileSize
new825 bytes

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
StatusFileSize
new813 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
StatusFileSize
new1.29 KB
new2.15 KB
new2.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
StatusFileSize
new2.38 KB
new1.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
StatusFileSize
new2.37 KB
new1.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
StatusFileSize
new2.5 KB
new1.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
StatusFileSize
new4.29 KB
new4.17 KB
new1.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
StatusFileSize
new4.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.