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
- Confirm suggested approach
- Implement a fix
User interface changes
None
API changes
None
Data model changes
None
Release notes snippet
N/A