Problem/Motivation
When having multiple formats which allow separate profiles, and at least one format is not loaded until after the initial page load, the module includes all CKEditor plugin translations in the AJAX response.
If JS aggregation is not used, this could lead to the webserver or a reverse proxy returning 429 "Too many requests" because of all the files.
Steps to reproduce
- Install a Standard Drupal profile.
- Download and enable a module which can cause editor instances to be loaded on demand, like Inline Entity Forms (or Paragraphs).
- Ensure the following modules are enabled: Locale, CKEditor 5, Inline Entity Forms.
- Disable JS aggregation
- Create two formats with separate CKEditor profiles, let's call them Simple and Advanced. Ensure Advanced uses more plugins than Simple.
- Set up two content types, also Simple and Advanced. Configure their body fields to only use the respective format.
- Give the Page content type an entity reference field, configured to reference the Simple and Advanced content types, and make sure the form uses the Complex widget
- Add at least one other language and switch to using it for the interface from here.
- Add a new Page node
- Select to add an inline Simple node, the first set of CKEditor plugins and their translations will be loaded.
- Remove the added node (can be skipped if cardinality was set >1)
- Add a new Advanced node, the next set of plugins will be loaded, but translations for all languages will be downloaded.
The problem lies in Drupal\ckeditor5\Hook\Ckeditor5Hooks::jsAlter
, which checks if a placeholder script/library was added to the response, and then filters out all CKEditor plugin translations.
On the AJAX request loading the second instance the placeholder library is in the list of already loaded libraries, and the placeholder script is therefor not included in the $javascript
array, so no filtering is performed for the newly added plugin translation libraries.
Proposed resolution
If the placeholder script is not present, look for an already loaded translation library and perform the filtering anyway if one was found.
Remaining tasks
Look for side-effects of the proposed resolution.
User interface changes
None