NULL Returned in `Drupal\Core\Asset\JsCollectionOptimizerLazy::optimizeGroup()`

Created on 5 February 2024, 5 months ago
Updated 13 February 2024, 5 months ago

Problem/Motivation

After upgrading from Drupal 9 to 10, JS scripts are not working. This is due to the following error:
```
TypeError: Drupal\Core\Asset\JsCollectionOptimizerLazy::optimizeGroup(): Return value must be of type string, null returned in Drupal\Core\Asset\JsCollectionOptimizerLazy->optimizeGroup() (line 185 of core/lib/Drupal/Core/Asset/JsCollectionOptimizerLazy.php).
Drupal\system\Controller\AssetControllerBase->deliver(Object, 'js__rpfGUkboRUBAZE_KH_2GRWjPWshR9E-CfkBDtLMm1g.js')
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
```

It seems there is a "cleaning" process that ends up returning NULL instead of the actual contents of the aggregated file.
Commenting out this line at https://github.com/drupal/drupal/blob/10.1.6/core/lib/Drupal/Core/Asset/... and just returning $data "resolves" the issue.

I'm not sure why the clean method is removing everything as it seems it should only remove source mapping URLs if I'm understanding the purpose correctly.

To my knowledge, the JS files should be compatible with Drupal 10 as the primary update of switching to the `once()` function has been made.

Unfortunately, I have not seen this issue on other projects and other similar issues posted that I've seen do not seem to stem from the same error.

Steps to reproduce

This issue occurs when JS aggregation is enabled.

Visiting any page where the JS is leveraged, and the aggregated file is needed, will trigger the issue.

πŸ’¬ Support request
Status

Active

Version

10.1 ✨

Component
Asset libraryΒ  β†’

Last updated 5 days ago

No maintainer
Created by

πŸ‡ΊπŸ‡ΈUnited States SirJohn96

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @SirJohn96
  • πŸ‡ΊπŸ‡ΈUnited States cilefen

    This is marked as a support request. Are you asking for support or reporting a bug? If it is a bug report, we are going to need more detailed steps to reproduce.

    Also, there are changes and improvements to the assets system in Drupal 10.2.

  • I have run into the same issue with a similar situation. Update from 9.5 -> 10.2.3. Aggregated JS files report the error notated in the original post.

    Disabling JS Aggregation makes the problem go away.

    Keeping JS Aggregation enabled but updating the line that @SirJohn96 outlined makes the problem go away.

    I'm attaching a patch for others' use if they run into this until we can figure out why.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Environment: PHP 8.1 & MariaDB 10.3.22
    last update 5 months ago
    29,722 pass
Production build 0.69.0 2024