Problem/Motivation
When trying to use our Font Awesome 6 Pro library, the icon picker in the toolbar shows a loading icon and then throws a JavaScript error in the console and never loads the list. The error is shown below:
Uncaught (in promise) CKEditorError: collection-add-item-invalid-index
Read more: https://ckeditor.com/docs/ckeditor5/latest/support/error-codes.html#error-collection-add-item-invalid-index
i http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
addMany http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
add http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
_startTracking http://testsite-com.ddev.site/modules/contrib/ckeditor5_icons/js/build/icon.js?s8fyo5:1
d http://testsite-com.ddev.site/modules/contrib/ckeditor5_icons/js/build/icon.js?s8fyo5:1
fire http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
_populateGrid http://testsite-com.ddev.site/modules/contrib/ckeditor5_icons/js/build/icon.js?s8fyo5:1
refresh http://testsite-com.ddev.site/modules/contrib/ckeditor5_icons/js/build/icon.js?s8fyo5:1
d http://testsite-com.ddev.site/modules/contrib/ckeditor5_icons/js/build/icon.js?s8fyo5:1
fire http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
d http://testsite-com.ddev.site/modules/contrib/ckeditor5_icons/js/build/icon.js?s8fyo5:1
_createIconPickerView http://testsite-com.ddev.site/modules/contrib/ckeditor5_icons/js/build/icon.js?s8fyo5:1
init http://testsite-com.ddev.site/modules/contrib/ckeditor5_icons/js/build/icon.js?s8fyo5:1
r http://testsite-com.ddev.site/modules/contrib/ckeditor5_icons/js/build/icon.js?s8fyo5:1
promise callback*a http://testsite-com.ddev.site/modules/contrib/ckeditor5_icons/js/build/icon.js?s8fyo5:1
s http://testsite-com.ddev.site/modules/contrib/ckeditor5_icons/js/build/icon.js?s8fyo5:1
s http://testsite-com.ddev.site/modules/contrib/ckeditor5_icons/js/build/icon.js?s8fyo5:1
init http://testsite-com.ddev.site/modules/contrib/ckeditor5_icons/js/build/icon.js?s8fyo5:1
fire http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
set http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
render http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
fire http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
R http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
fire http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
click http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
s http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
fire http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
t http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
attach http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
_addEventListener http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
listenTo http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
listenTo http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
listenTo http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
listenTo http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
activateDomEventListener http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
o http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
_setUpListeners http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
_renderElement http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
_renderNode http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
render http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
render http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
render http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
render http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
decorate http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
fire http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
e http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
_renderElementChildren http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
_renderElement http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
_renderNode http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
render http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
render http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
render http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
decorate http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
fire http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
e http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
_renderViewIntoCollectionParent http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5
l http://testsite-com.ddev.site/core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js?v=40.2.0:5Steps to reproduce
- Enable and configure the main Font Awesome module with Font Awesome Pro, providing the library locally (/libraries/fontawesome)
- Enable this module, edit your main text format and add the "Icons" button to the toolbar.
- In the configuration for "Icons" switch from "Font Awesome Free" to "Custom".
- Create or edit a page and in a section using the editor you have configured, click on the Icons button to insert an icon.
| Comment | File | Size | Author |
|---|---|---|---|
| #20 | ckeditor5_icons-3419525-2.patch | 88.09 KB | timurtripp |
Issue fork ckeditor5_icons-3419525
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
Comment #2
ari.saves commented+1 I'm also having this issue; same behavior, though I get a console error too:
Comment #3
agbockus commentedOh, interesting - after updating from Font Awesome Pro
6.4.2to6.5.1, the previous error goes away - but I now get the "trim is not a function" error from the comment above!Comment #4
agbockus commentedAlright, was able to take a look at this and found the spots that were throwing errors. It seems like it ended up passing
-1as theindex, when CKEditor will assign one for us if it doesn't have an index. That, and not callingtrimon an empty orvoidseemed to fix my issues and got it working for me.Comment #5
timurtripp commentedAdding it with no index works but that unfortunately breaks the focus tracker item order. The index is there to ensure the focusable the elements are in the correct order when using keyboard-based navigation.
Comment #6
timurtripp commentedComment #7
timurtripp commentedHere's a patch to fix the error in the OP. The error is triggered whenever the "Expand" button is visible on the initial opening of the icon picker (Font Awesome Free has fewer icons and wasn't triggering this), so good catch on that one.
"e.trim is not a function" is unrelated and shouldn't happen unless your Font Awesome metadata is somehow corrupted, or maybe there's a bug in your specific version of the metadata. I don't have access to your custom Font Awesome Pro metadata so more information would be helpful, such as the value of `e` (the specific search term that's not a string), and which icon it's breaking on. Because this is an open-source project, you can use `npm run watch` to get a more verbose copy of the script for setting breakpoints / other debugging purposes.
Comment #8
timurtripp commentedComment #10
timurtripp commentedComment #11
agbockus commentedI had updated the Font Awesome library with a fresh download, so the metadata was straight from them - but maybe it was just a secondary issue from the main index issue.
Yeah, originally I had logged the
indexvariable and it printed twice as1and then once as-1, which CKEditor didn't seem to like. After looking at CKEditor documentation, it says that not providing an index would add it to the collection (and assumedly create an index value). Just to get something working, it made sense to let them handle the index versus providing a value that threw an error.The patch in #7 changes the logged
indexvalue in_startTracking()from1, 1, -1to1, 2, undefined, but CKEditor doesn't throw an error and continues working!So overall, the patch provided in #7 seems to solve the issue - the icon picker now displays and inserts icons! Thanks for the patch!
Comment #12
timurtripp commentedundefinedis okay in some situations, theindexparameter is optional and predictably it'll just append to the end if not specified. I'll go ahead and merge this in, thanks!Comment #14
timurtripp commentedComment #15
agbockus commentedAlright, after some more testing and putting this on another site, I've started encountering the "e.trim() is not a function" error again.
After logging the value of
termon line 89 iniconutils.ts, it prints them all up to0- which prints as anumber, not astring. I believe this is why we're getting the "e.trim() is not a function" error.Should that line be modified to only trim strings?
Alternatively, it might be being imported as a number instead of a string - but this is still with a brand new download of FA6 Pro from Font Awesome, so it might just be how they populate some of the Pro icons vs Free?
Comment #16
timurtripp commentedThey may have introduced a bug into their metadata YAML file, but it's something we can account for. Do you have the section of their YAML file that's breaking it?
Comment #17
timurtripp commentedSomething like a
- 0instead of- '0'I assume.Comment #18
agbockus commentedOh, looks like that may be the exact issue!
There are a few instances - in their
icons.ymlthey have it underplusandplus-large:There are similar lines in the
icon-families.ymlfor the same icons too!Comment #19
timurtripp commentedYep that'll do it. The Font Awesome module has no check to ensure these are all strings, and doesn't trim them either (which likely breaks some terms for the module's own autocomplete widget, I've seen a bunch that needed trimming which is why I added that). Since this module is pulling the metadata directly from the Font Awesome module when "Custom" gets selected, the issue gets passed down the pipeline.
Comment #20
timurtripp commentedNew patch to make TypeScript expect either a
stringornumberinstead ofstringonly, let me know if this works.Comment #21
timurtripp commentedComment #22
ari.saves commentedThe patch in #20 resolves the e.trim error for me! Thanks so much :)
I'm still having some issues getting custom icons to show in the plugin window. Wondering if my metadata is corrupted.
Here's some metadata for a custom icon:
vs the metadata for a FA icon:
So a lot more attributes there for the FA icon vs our custom kit icons; wondering which of these attributes may be required and if that's the issue.
Comment #23
timurtripp commented@ari.saves Thanks! I'd like to close this issue about the JavaScript error, feel free to open a separate one for the custom icons not showing up in the picker and I'll credit you once a fix is available for that.
Comment #25
timurtripp commented