Stylesheets in 'ckeditor5-stylesheets' are not checked for existence before being included

Created on 8 December 2023, 9 months ago

Problem/Motivation

`ckeditor5-stylesheets` property set in theme's info.yml file is used to include stylesheets into CKEditor 5 document.

If the included stylesheet does not exists - it will still be requested from the server. If this happens during an AJAX request (like when you edit a collapsed Paragraph content) - the request will fail with Refused to apply style from 'http://localhost/sites/default/files/custom.css?s5c3ut' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled. and the post-request action will never complete (the collapsed Paragraph will not open).

ckeditor5_theme_css() has the following code:

        // CSS URL is external or relative to Drupal root.
        if (UrlHelper::isExternal($url) || $url[0] === '/') {
          $css[$key] = $url;
        }
        // CSS URL is relative to theme.
        else {
          $css[$key] = '/' . $theme_path . '/' . $url;
        } 

There is no check for an existence of the resource before it is included.

Steps to reproduce

1. Create a theme
2. Specify in theme's `info.yml` file:

ckeditor5-stylesheets:
  - some-non-existing.css

3. Clear the cache
4. Go to the page with CKEditor loaded
5. Observe the message in the web-browser console or in the network tab that a request was made to the some-non-existing.css file.

Proposed resolution

Add a check for existence for local resources and trigger a warning or a notice if the resource does not exist.

Remaining tasks

  1. Confirm suggested approach
  2. Implement a fix

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

N/A

🐛 Bug report
Status

Active

Version

10.1

Component
CKEditor 5 

Last updated 2 days ago

Created by

🇦🇺Australia alex.skrypnyk Melbourne

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

    It involves the content or handling of Cascading Style Sheets.

Sign in to follow issues

Comments & Activities

  • Issue created by @alex.skrypnyk
  • 🇮🇳India ravi kant Jaipur

    I am not getting error if i apply style same as example.

    ckeditor5-stylesheets:
      - dist/css/ck_editor--template.css
    

    If i uses library as below example then getting error.

    ckeditor5-stylesheets:
      - rk/newfile
    

    Error -

    ajax.js?v=10.1.5:1118 An error occurred during the execution of the Ajax response: The following files could not be loaded: /themes/custom/rk/rk/newfile?s5cjks0
    

    But working fine if i extending library -

    libraries-extend:
      core/ckeditor5:
        - rk/newfile
    
Production build 0.71.5 2024