Handle invalid compressed ajax_page_state more gracefully

Created on 24 January 2024, about 1 year ago
Updated 17 May 2024, 10 months ago

Problem/Motivation

Was: Warning: Undefined array key 1 in Drupal\Core\Asset\LibraryDependencyResolver->doGetDependencies() after update to Drupal 10.2.2 and when views ajax is enable.

After update Drupal core to Drupal 10.2.2 we can see a warning.

Warning: Undefined array key 1 in Drupal\Core\Asset\LibraryDependencyResolver->doGetDependencies() (line 72 of core/lib/Drupal/Core/Asset/LibraryDependencyResolver.php).
Drupal\Core\Asset\LibraryDependencyResolver->doGetDependencies(Array) (Line: 41)
Drupal\Core\Asset\LibraryDependencyResolver->getLibrariesWithDependencies(Array) (Line: 118)
Drupal\Core\Asset\AssetResolver->getLibrariesToLoad(Object) (Line: 132)
Drupal\Core\Asset\AssetResolver->getCssAssets(Object, , Object) (Line: 149)
Drupal\Core\Ajax\AjaxResponseAttachmentsProcessor->buildAttachmentsCommands(Object, Object) (Line: 117)
Drupal\Core\Ajax\AjaxResponseAttachmentsProcessor->processAttachments(Object) (Line: 62)
Drupal\Core\EventSubscriber\AjaxResponseSubscriber->onResponse(Object, 'kernel.response', Object)
call_user_func(Array, Object, 'kernel.response', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.response') (Line: 214)
Symfony\Component\HttpKernel\HttpKernel->filterResponse(Object, Object, 1) (Line: 202)
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: 53)
Asm89\Stack\Cors->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: 25)

I believe that it is caused by [#3389367].
A debug shows that our library passed to explode function is:
eJyFVWuSmzAMvpCBmU57gJ7EI4wC3vjBSHI22dPXNoEEurR_bEvfZ2E9gcHboCVG1wN1z70VQlRwCrVTvCHZIBhkT9OMQGbqlu2AlZ03Q9bEoHoHX4-ut7GFD7irPkZhIZh_dj0w7uTt2Hxw40CQ5R0fKM3g2gC3RqDnd2h0sQfXsDycDeM74pEZRmSV3yJ4lwRuNfTSNPnW9T-Up1OZRLjCYMTesN5e9CGSB2e_UA14w2ymrNvVgexFurqqCxgUXg0tUmsmNNc-3ptPO4x4QposUgm9NeC-Z9wsfnJTw33JOdC9i2P3GenaYzDTmqwFGzFkc66redyrtii2fQqDwxNUj2SHM4ywnM_QJNZZsTk7ewIhDIaS77m83Vz3sJkoepu8Li4Bxfy4PcFZllwG_IyHvlgnSKzZkJ3ljLuQ_o3qxeKe5DGk1sMxfDMQjNnLqTUC-gZkIYj-dUpKLNFj7i-JlEOin98-4085Rpm92v2x5xGONob2kkONh0zzgwV9O-euOCAyoUd9yTXP3wFL-L6HcuMhT_iKzdtceVXe2p-VUiJ2UmN76K3ADsB7dR2gQ2lV9C__3rQ75yJDiF1dVfakK96AMWUWrmIdXqtggxU12ZK5R-eBrg1wU4pY1eFXFrVlbuvWl6ZNYU59TviEgyLkOQbOg0XPhKWX1wsvpHkiilFqgers9GPl7ZSKp0hikmzoU1ZLISxjWPzoN0YV2nVMHH4PR7lFNjDj7zo_JKYCJFKJkVZ75Vx_BqzqaOrq2vo4pJzxKugyrfQawueutsp51dD6rD-P_652

so after calling caller stack, I can see that it is:

$assets->setLibraries($attachments['library'] ?? [])
      ->setAlreadyLoadedLibraries(isset($ajax_page_state['libraries']) ? explode(',', $ajax_page_state['libraries']) : [])
      ->setSettings($attachments['drupalSettings'] ?? []);

from AjaxResponseAttachmentsProcessor.php

Caller stack:

<ROOT>/core/lib/Drupal/Core/Asset/LibraryDependencyResolver.php:41 Drupal\Core\Asset\LibraryDependencyResolver->doGetDependencies(array $libraries_with_unresolved_dependencies, array $final_libraries = array())
ā‡„ā§‰<ROOT>/core/lib/Drupal/Core/Asset/AssetResolver.php:118 Drupal\Core\Asset\LibraryDependencyResolver->getLibrariesWithDependencies(array $libraries)
ā‡„ā§‰<ROOT>/core/lib/Drupal/Core/Asset/AssetResolver.php:132 Drupal\Core\Asset\AssetResolver->getLibrariesToLoad(Drupal\Core\Asset\AttachedAssetsInterface $assets)
ā‡„ā§‰<ROOT>/core/lib/Drupal/Core/Ajax/AjaxResponseAttachmentsProcessor.php:149 Drupal\Core\Asset\AssetResolver->getCssAssets(Drupal\Core\Asset\AttachedAssetsInterface $assets, $optimize, ?Drupal\Core\Language\LanguageInterface $language = null)
ā‡„ā§‰<ROOT>/core/lib/Drupal/Core/Ajax/AjaxResponseAttachmentsProcessor.php:117 Drupal\Core\Ajax\AjaxResponseAttachmentsProcessor->buildAttachmentsCommands(Drupal\Core\Ajax\AjaxResponse $response, Symfony\Component\HttpFoundation\Request $request)
ā‡„ā§‰<ROOT>/core/lib/Drupal/Core/EventSubscriber/AjaxResponseSubscriber.php:62 Drupal\Core\Ajax\AjaxResponseAttachmentsProcessor->processAttachments(Drupal\Core\Render\AttachmentsInterface $response)

Steps to reproduce

We have standard views solr block with ajax enabled and facets. When we change options in facets, we can see warnings like that.
If we disabled ajax, then warnings disappeared.

Proposed resolution

Merge request link

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

šŸ› Bug report
Status

Fixed

Version

10.2 āœØ

Component
Asset libraryĀ  ā†’

Last updated about 12 hours ago

No maintainer
Created by

šŸ‡µšŸ‡±Poland lamp5 Rzeszow

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024