Problem/Motivation

Without CSP Extras, the core AJAX system use jQuery "insert" method which seems to trigger correctly new behaviors added in the scripts loaded through AJAX.

The method used by CSP Extras does not and this generates problems when newly added script behaviors should be triggered immediately.

Steps to reproduce

  1. Create a Paragraph Type with a Wysiwyg Field
  2. Create a Content Type with a Paragraph field configured to use the widget "Paragraphs Classic", the Edit mode "closed" and "None" in the "Default paragraph type" select list.
  3. Go to the node creation page
  4. Press the button "Add [paragraph type]"
  5. The textarea field appears but the wysiwyg is not applied on

Proposed resolution

The problem here is that the scripts added by the CSP Extras method "add_assets" are not yet loaded when the textarea field is added by Drupal.
So the Drupal.attachBehaviors() is triggered to early, at a moment when the "CKEditor" behaviors are not available.

A solution could be to use Javascript Promises to trigger Drupal.attachBehaviors() after the scripts are loaded.
It's what the attach patch do.

CommentFileSizeAuthor
#2 csp-3214916-2.patch1010 bytesnixou

Issue fork csp-3214916

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

Nixou created an issue. See original summary.

nixou’s picture

Status: Active » Needs review
StatusFileSize
new1010 bytes
design.er’s picture

Patch from #2 is working like a charm. Thank you for putting it together.

gapple’s picture

Status: Needs review » Needs work

Thank you for the issue report, patch, and review 🙂.

Drupal 8 and 9 continue to support IE 11, which doesn't appear to support Promise - I would like to have a fallback to maintain compatibility with IE.

----

If you're familiar with this issue, your feedback on these core issues which would remove the need for CSP to do this in D9 could also be valuable:
#3228351: Add loadjs library
#3228352: Add an add_js ajax command that uses promises
#1988968: Drupal.ajax does not guarantee that "add new JS file to page" commands have finished before calling said JS

bartlangelaan made their first commit to this issue’s fork.

bartlangelaan’s picture

Status: Needs work » Needs review

I changed the patch from #3 so it doesn't use promises anymore.

Please check out MR !3.

Taoufik Saadane’s picture

Status: Needs review » Reviewed & tested by the community

  • gapple committed d2d79db on 8.x-1.x authored by bartlangelaan
    Issue #3214916: Behaviors will not load after AJAX call when using CSP...
gapple’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.