Placeholders cannot attach drupalSettings if drupalSettings was loaded in header

Created on 7 January 2025, 3 days ago

Problem/Motivation

I noticed that if I attach a library that depends on drupalSettings, and load it in the <head> element, and then also have a placeholder that attaches something to drupalSettings, the new setting will not actually be attached when it's processed by Big Pipe module. Attaching settings from placeholders only works when drupalSettings is loaded at the bottom of the <body>

Steps to reproduce

  1. Enable bigpipe module
  2. Attach a library that has header: true and depends on core/drupalSettings. This will result in drupalSettings being output in the HTML <head> element.
  3. Add a placeholder that attaches something to drupalSettings, and a library that uses this setting
  4. Bigpipe module will attach the library, but will fail to attach the setting.
  5. The library will not be able to find the expected key in drupalSettings.

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component

big_pipe.module

Created by

πŸ‡ΊπŸ‡ΈUnited States mfb San Francisco

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

Comments & Activities

  • Issue created by @mfb
  • πŸ‡¬πŸ‡§United Kingdom catch

    BigPipe uses the AJAX system for this, so it's likely that if it can't do this, it's a general bug in the AJAX system (although might be harder to reproduce/write tests without big pipe).

  • πŸ‡ΊπŸ‡ΈUnited States mfb San Francisco

    A comment in Drupal\bigpipe\Render\BigPipe says

    If additional asset libraries or drupalSettings were attached by any of the placeholders, then we need to re-render scripts_bottom.

    - seemingly forgetting that we don't necessarily know where drupalSettings lives, maybe it was in the <head> element. Fingers crossed someone more knowledgeable about the AJAX system could figure out a good way to resolve this.. :)

  • πŸ‡ΊπŸ‡ΈUnited States mfb San Francisco

    AFAICT, the AJAX system seems to be able to merge new settings from an AJAX response into the global settings just fine, it's just not happening when BigPipe processes placeholders.

  • πŸ‡ΊπŸ‡ΈUnited States mfb San Francisco
  • πŸ‡ΊπŸ‡ΈUnited States mfb San Francisco

    @catch I did some more debugging on this and determined that this bug only affects manually created, non-markup placeholders, which are essentially skipped - although still broken - by BigPipe.

    Many placeholders will not be affected by this bug because they use automatically-created placeholders ('#create_placeholder' = TRUE)

  • πŸ‡ΊπŸ‡ΈUnited States mfb San Francisco
Production build 0.71.5 2024