Library attached in filter plugin is not rendered on the page in CKEditor 5 (Drupal 11)

Created on 13 July 2025, 22 days ago

Problem/motivation

In Drupal 11, using CKEditor 5, libraries attached via $result->setAttachments() in a filter plugin are not automatically rendered on the page unless they are explicitly declared in the text format’s configuration (filter.format.*.yml). The responsive_tables_filter module attaches the responsive_tables_filter/tablesaw-filter library in its process() method, but this library is not declared in the text format config, so the CSS/JS is not actually loaded in the frontend.

Steps to reproduce

  1. Enable the responsive_tables_filter module on a Drupal 11 site.
  2. Use a text format (e.g. Filtered HTML) with CKEditor 5 that has the Responsive Tables filter enabled.
  3. Add a table in the editor and save the content.]
  4. Observe that the responsive_tables_filter/tablesaw-filter library is not included in the rendered page.
🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇯🇴Jordan rahaf albawab Amman

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

Comments & Activities

  • Issue created by @rahaf albawab
  • 🇺🇸United States mark_fullmer Tucson

    Thanks for filing this report! I may need some help understanding the intent here, as my first analysis suggests this works as designed.

    The description above states that "In Drupal 11, using CKEditor 5, libraries attached via $result->setAttachments() in a filter plugin are not automatically rendered on the page unless they are explicitly declared in the text format’s configuration (filter.format.*.yml)."

    Would it be more accurate to say that the library is not attached unless the text format filter is executed as part of the page's rendering process?

    If not, can you point to a Drupal change record that spells this out, and/or an example in Drupal core or contrib where this is the case? I find it very plausible to expect that `$result->setAttachments()` won't execute on a page if the the filter format plugin isn't executed on the page, but I don't follow the logic that a Drupal library would need to be explicitly declared in a text format configuration in order to allow `$result->setAttachments()` to execute.

    Regardless, I don't find the Steps to Reproduce above to be true. When I create a text format with filter_responsive_tables_filter enabled and create a page that renders an HTML table with a header, I see the Tablesaw library loaded and working as designed.

    Furthermore, the proposed code change doesn't seem like the expected logic. By adding a hook_preprocess_page() hook, as indicated in the comments, if the Responsive Tables Filter plugin is added to *any* text format, it will add the library to *every* page, regardless of whether that page renders any content using the text format. This almost seems like using a "back door" of a text format filter to add the Tablesaw library to the entire site, which is not the design of the module.

    If sites do want to add the Tablesaw library to every single page, that's up to the developer I guess, and they could simply do the following, or add responsive_tables_filter/tablesaw-filter as a dependency to the site theme's library.

    function mymodule_preprocess_page(&$variables): void {
        $variables['#attached']['library'][] = 'responsive_tables_filter/tablesaw-filter';
    }
    
Production build 0.71.5 2024