After enabling the module, the following notice appears in the logs.

Notice: Undefined index: #tag in Drupal\http2_server_push\Asset\CssCollectionRenderer->render() (line 53...

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hitfactory created an issue. See original summary.

DamienMcKenna’s picture

Version: 8.x-1.0-beta1 » 8.x-1.x-dev
Status: Active » Needs review
FileSize
982 bytes

This is a workaround, but it'd be worthwhile checking to see what $element contains to see why those variables don't exist in case there's another bug (or API change) somewhere.

hitfactory’s picture

Confirming patch in #2 works and gets rid of notices.

FYI, the error is being thrown for $elements['prefetch'] which, in my case, is an empty array.

Wim Leers’s picture

Interesting! I wonder how one can reproduce this. On which URLs is this happening? AFAICT there are only two possible ways to get this:

  1. HTML responses with no CSS at all
  2. HTML responses with only external CSS

If that can be confirmed, then this will be committed & released right away :)

hitfactory’s picture

We have a request which runs on every page which returns a JSON response. Could it be that?

The request object returns the URL of the page I'm on so not sure how to check if it is the JSON route tripping it up.

Note that, we're also using the Advanced CSS/JS Aggregation module. Will check now to see if the error is still thrown without that module enabled.

Wim Leers’s picture

Thanks for checking those things!

hitfactory’s picture

After uninstalling Advanced CSS/JS Aggregation module, the notice disappears.

I see in Drupal\advagg\AssetCssCollectionRenderer, $elements['prefetch'] gets initialized to an empty array so if that is valid, then I guess the patch is needed after all.

Wim Leers’s picture

Title: Notice: Undefined index: #tag » CSS Collection Renderer decorator iterates over all render array elements, should only iterate over children
FileSize
1.24 KB

So indeed, advagg is doing this:

$elements = ['prefetch' => []];

in \Drupal\advagg\Asset\CssCollectionRenderer::render().


The solution in #2 works, but is not quite correct. I think this is correct.

Status: Needs review » Needs work

The last submitted patch, 8: 2842347-8.patch, failed testing.

Wim Leers’s picture

Status: Needs work » Needs review
hitfactory’s picture

'prefetch' is returned as one of the values in Element::children($elements) so undefined index notice is back with patch in #8.

Looks like a combination of #2 and #8 is required as it seems the isset($element['#tag']) check is still needed.

Wim Leers’s picture

Advagg just released version 2.2 to fix this: http://cgit.drupalcode.org/advagg/commit/?h=8.x-2.x&id=0396b6a799a09ea47....

Sadly, the fix is incomplete; in fact, it causes D8 to break entirely. Once #2859132: Error: Unsupported operand types in Drupal\advagg\Render\HtmlResponseAttachmentsProcessor->processAssetLibraries() (line 64) is in, this is really fixed. Once that's also fixed in Advagg, then this problem will have disappeared.

Wim Leers’s picture

Assigned: Unassigned » Wim Leers
FileSize
1.84 KB

However, that being said, I now see that #8 was completely wrong. I even wonder now what I was thinking then :)

The code in http2_server_push should simply be more robust. So, here's the code to make that more robust.

Wim Leers’s picture

FileSize
5.16 KB
5.46 KB

#13 fixes the problem. But let's be super thorough so that we don't ever have to deal with this again. Let's make it really ensure all assumptions are met, and let's fix it not only in \Drupal\http2_server_push\Asset\CssCollectionRenderer but also in \Drupal\http2_server_push\Asset\JsCollectionRenderer.

Wim Leers’s picture

FileSize
508 bytes
5.14 KB
+++ b/src/Asset/AssetHtmlTagRenderElementTrait.php
@@ -0,0 +1,69 @@
\ No newline at end of file

Fixing this nit.

Wim Leers’s picture

Title: CSS Collection Renderer decorator iterates over all render array elements, should only iterate over children » Notice: Undefined index: #tag when used with the "Advanced CSS/JS Aggregation" module
Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community

Zero coding standards violations:

wimleers in ~/Work/d8 on 8.4.x*
$ phpcs modules/http2_server_push --standard="core/phpcs.xml.dist"

  • Wim Leers committed ccf212b on 8.x-1.x
    Issue #2842347 by Wim Leers, DamienMcKenna, hitfactory: Notice:...
Wim Leers’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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