Return ajax_page_state['libraries'] via a header

Created on 12 November 2024, 2 days ago

Problem/Motivation

We currently follow the existing pattern in core in which drupalSettings.ajaxPageState.libraries is returned with each request as a query parameter. The works to keep the asset libraries in sync. However, in core only automated processes see these urls. With HTMX if hx-push-url is used with true the url of the request is pushed to the location bar.

Proposed resolution

Given the work done in πŸ“Œ Compress ajax_page_state Fixed , move the transmission of page state from a query parameter to a header. The compression should keep this string well within the 8K bytes (8K UTF-8 characters) limit imposed by the most common web servers.

Refactor htmxDrupalPageState to place drupalSettings.ajaxPageState.libraries in an HX-Page-State header.
Refactor HtmxResponseAttachmentsProcessor::processAssetLibraries to begin with code to process the header. Just before this method is called the parent runs

$ajax_page_state = $this->requestStack->getCurrentRequest()->get('ajax_page_state');
$assets->setAlreadyLoadedLibraries(isset($ajax_page_state) ? explode(',', $ajax_page_state['libraries']) : []);
πŸ“Œ Task
Status

Active

Version

1.3

Component

Drupal Code

Created by

πŸ‡ΊπŸ‡ΈUnited States fathershawn New York

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024