If a library is added during an ajax request, the drupalSettings.ajaxPageState.libraries contains duplicate values.

This is a performance issue when using POST ajax request but becomes an major issue if the ajax is made with GET because after each ajax request the URI for the next ajax request becomes larger and at some point it becomes larger than allowed and a "414 Request-URI Too Large" is possible.

Issue fork drupal-2868737

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

braindrift created an issue. See original summary.

braindrift’s picture

braindrift’s picture

Status: Active » Needs review
codesmith’s picture

This worked great for me - thanks!

codesmith’s picture

Version: 8.2.x-dev » 8.4.x-dev

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dawehner’s picture

@codesmith

+++ b/core/modules/system/system.module
@@ -726,6 +726,7 @@ function system_js_settings_alter(&$settings, AttachedAssetsInterface $assets) {
+    $minimal_libraries = array_unique($minimal_libraries);

Here is a suggestion: Move this array_unique call into \Drupal\Core\Asset\LibraryDependencyResolver::getMinimalRepresentativeSubset This way unit testing in \Drupal\Tests\Core\Asset\LibraryDependencyResolverTest would totally be possible.

it-cru’s picture

@dawehner : I will refactor previous patch and try to provide it today.

@dawehner : Or is this already fixed in the 8.6.x branch? But I think it only checks this with assert, but does not filter given libraries via array_unique for further processing.

it-cru’s picture

Version: 8.5.x-dev » 8.6.x-dev
it-cru’s picture

Move array_unique filtering of libraries array to \Drupal\Core\Asset\LibraryDependencyResolver::getMinimalRepresentativeSubset as suggested from @dawehner.

dawehner’s picture

Issue tags: +Needs tests

@dawehner : Or is this already fixed in the 8.6.x branch? But I think it only checks this with assert, but does not filter given libraries via array_unique for further processing.

Do you understand why it produces duplicates? Maybe we can fix this different.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

joelpittet’s picture

Status: Needs review » Needs work

The assert right above is already checking for duplicates, I think if there are duplicates we need to find the source(and tests).

assert(count($libraries) === count(array_unique($libraries)), '$libraries can\'t contain duplicate items.');

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

larowlan’s picture

Status: Needs work » Postponed (maintainer needs more info)
Issue tags: +Bug Smash Initiative

Per #11 and #13

it-cru’s picture

We don't use this AJAX requests in our projects anymore which was reported by @braindrift in the past, because we already switched to a decoupled frontend solution.

Maybe it comes up from our library handling in our custom parent / child themes we used here in the past.

Perhaps it would be good to replace the assert() call in getMinimalRepresentativeSubset() of LibraryDependencyResolver class to some try catch to get more informations on production environments from other projects which seems to have also this issue.

assert() is a language construct in PHP 7, allowing for the definition of expectations: assertions that take effect in development and testing environments, but are optimised away to have zero cost in production.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)

Closing out as outdated per #20.

Not something that's been noticed I believe/reproducible.

mkalkbrenner’s picture

Status: Closed (outdated) » Active

I just updated a site from Drupal 9.5.10 to 10.1.0 and run into this error now.

I debugged the issue and found that views/views.module is added twice.

mkalkbrenner’s picture

In Drupal\Core\Render\HtmlResponseAttachmentsProcessor::processAttachments():

$ajax_page_state = $this->requestStack->getCurrentRequest()->get('ajax_page_state');

This page state contains views/views.module two times.

mkalkbrenner’s picture

Status: Active » Needs work
StatusFileSize
new693 bytes

This quick fix made the site work in the dev environment.

mkalkbrenner’s picture

Also happens with 10.1.1.
But it is interesting that it wasn't an issue with 9.5.x.

it-cru’s picture

@mkalkbrenner: Maybe HTTP method for AJAX requests has changed to GET in D10 or D10.1? This was in the past our problem, because we used some patch I think to have GET instead of POST request for AJAX in our project.

Could you double check this? As mentioned in #21 with switch to a decoupled frontend we do not trigger such AJAX requests in our project anymore.

thtas’s picture

I've just run in to this too.

it does only seem to manifest during during tests run via weitzman ExistingSiteBase tests, but when i step through myself in the brower the libraries are unique.

We're not doing any ajax requests, and the problem goes away when I disable big_pipe.

The library which is being added twice is "facets/drupal.facets.link-widget" (and it's duplicated at the end of the libraries array).

Super odd. I've run out of time to dig any deeper so have just applied the patch :(

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

kwinten-hardies’s picture

Looks like this is still the case with Drupal 11.0.1 too. I just tested this on a standard install of Drupal 11 with only media en media_browser enabled as extra.
When filtering and paginating, the query parameters are duplicated. resulting in a "request URI too long" error on our firewall.

From 10.2.3 onwards this is a problem for all our site's. I found a lot of issues regarding this but all proposed solutions do not work.
Could this be a nginx problem? But I tried this on a docker-drupal setup with apache and it's the same there.

I just don't know where to look in ajax code. Please advise. Thank you.

mohit_aghera’s picture

I also noticed this issue while working on the project.
Drupal core: 10.3.10 with big_pipe module enabled.
Issue was noticed on layout builder edit form where core/components.navigation--toolbar-button library was added twice.

Upon debugging, I noticed that it is present twice in ajax_page_state as well.

I think we should apply array_unique when we push the libraries to ajax_page_state so we always have unique libraries in the ajax_page_state.

I've added a PR with the fix.

mohit_aghera’s picture

Adding patch for the 10.3.x release cycle since current 11.x patch is not cleanly applied on 10.3.x.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.