Problem/Motivation

From #2368797-50: 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:

+++ b/core/lib/Drupal/Core/Ajax/AjaxResponse.php
@@ -26,6 +27,32 @@ class AjaxResponse extends JsonResponse {
+  public function setAttachments(array $attachments) {
+    $this->attachments = $attachments;
+    return $this;
+  }

This method just replaces the attachments with a new value. Thinking also about #2347469: Rendering forms in AjaxResponses does not attach assets automatically, we may have several Ajax commands in a response, each targeting a different portion of the form, and each having its own attached assets. So, wouldn't it make sense to have a method that incrementally merges the input instead?

Proposed resolution

TBD

Remaining tasks

TBD

User interface changes

None.

API changes

TBD

Comments

andypost’s picture

So we are going to... depending on a kind of response to manage assets differently?

wim leers’s picture

Status: Postponed » Active

The parent issue landed, we can work on this now.

wim leers’s picture

Status: Active » Needs review
StatusFileSize
new27.57 KB

Et voila.

wim leers’s picture

#1: Basically: yes. Before #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, we implicitly relied on statics in _drupal_add_(css|js)(). We've been working towards removing those for several years. Finally it has happened. For HTML responses, we render everything inside html.html.twig, and then use #attached to determine which <script> and <link rel="stylesheet"> tags to render. For AJAX responses, we don't have that; there can be multiple AJAX commands in an AJAX response, each needing assets, and potentially the same. Hence :;addAttachments().

wim leers’s picture

StatusFileSize
new30.2 KB
new3.13 KB

Addressing #2368797-65: 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, point 3:

+++ b/core/lib/Drupal/Core/Render/MainContent/AjaxRenderer.php
@@ -84,9 +85,7 @@ public function renderResponse(array $main_content, Request $request, RouteMatch
   protected function drupalRenderRoot(&$elements) {
-    $output = drupal_render_root($elements);
-    drupal_process_attached($elements);
-    return $output;
+    return drupal_render_root($elements);
   }

Follow-up, but this should have the renderer injected or not?

Status: Needs review » Needs work

The last submitted patch, 5: 2407201-5.patch, failed testing.

The last submitted patch, 3: 2407201-3.patch, failed testing.

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new30.21 KB
new1.17 KB

Oops.

Status: Needs review » Needs work

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

wim leers’s picture

Assigned: Unassigned » wim leers
wim leers’s picture