drupalSettingsLoader removes changes in DrupalSettings added in ajax requests

Created on 15 November 2023, about 1 year ago

Problem/Motivation

The drupalSettings global object is first built by using values in the html <script[data-drupal-selector="drupal-settings-json]> tag.

Additional settings might be added to the global drupalSettings through ajax requests. Think of ckeditor instances added to text fields that open in a modal.

Sometimes, the drupalSettingsLoader get's reloaded. Since it doesn't check if the drupalSettings already exist, it overwrites whatever was added by taking the values in the html <script[data-drupal-selector="drupal-settings-json]>.

See drupalSettingsLoader.js

Steps to reproduce

I'm not sure if this can be reproduced easily, but i have bumped into this problem using several contrib modules, (ief, entity_browser, ajax_comments) and have come to the conclusion that this is a core issue.

It should be possible to reproduce this issue writing a test.

1. open an node form in a modal, check that the editor settings are added to drupalSettings using the browser console.
2. Execute an ajax command that sets some drupal setting.
3. Check drupalSettings global in the browser console: editor settings have dissappeared.

Proposed resolution

Only set drupalSettings based on the data-attribute in HTML if drupalSettings doesn't exist already.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Active

Version

10.2 ✨

Component
AjaxΒ  β†’

Last updated 3 days ago

Created by

πŸ‡ͺπŸ‡ΈSpain nuez Madrid, Spain

Live updates comments and jobs are added and updated live.
  • JavaScript

    Affects the content, performance, or handling of Javascript.

Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024