Word count error if more than one CKEditor on the page is added via ajax

Created on 25 April 2024, 2 months ago
Updated 14 June 2024, 12 days ago

I tried to use the word count module, but it stopped all the ckeditor instance on the page after the first one is loaded.

I tried this module, and it does not cause the issue:

https://www.drupal.org/project/ckeditor5_word_count β†’

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States duckydan

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

Merge Requests

Comments & Activities

  • Issue created by @duckydan
  • Status changed to Postponed: needs info 2 months ago
  • πŸ‡΅πŸ‡±Poland dolszewski

    Hello @duckydan
    We will need more information about your issue.
    What do you mean by "all the ckeditor instance on the page"? Do you have multiple fields with the editor on the node edit page?
    Which version of Drupal do you use?
    Can you send some screenshots and errors from the console?
    Do you use any other contrib module for ckeditor5?

  • πŸ‡ΊπŸ‡ΈUnited States duckydan

    Hi,

    Here is using this module versus the other module.

    Two active editor instances on the page:

    ckeditor5_word_count

    This module

    Error:

    [Error] TypeError: null is not an object (evaluating 'this.wordCountWrapper.appendChild')
    init β€” js_zOFaiI9NhmzRFDJtbTw54krp_rYkGjyLTbct6SSnvLg.js:40
    
    	(anonymous function) (js_ls5PfL4dqY75JAnrMyM9p9UF5jrVzr1c07bF4EJVVTA.js:17:5449)

    Environment:

    Drupal version 10.2.5
    PHP version 8.1.12

    I have these modules installed:

  • πŸ‡΅πŸ‡±Poland salmonek

    Hi @duckydan
    Is there any chance that some custom code is adding own '#suffix' to the textarea?

  • Status changed to Active 2 months ago
  • πŸ‡ΊπŸ‡ΈUnited States duckydan

    I switched it to active after providing this info. I hope that was OK.

  • πŸ‡ΊπŸ‡ΈUnited States duckydan

    My custom code is really limited. It is for stuff like emails and creating and removing nodes behind the scenes. Nothing that would do something like that.

    The additional ckeditor instances show up via Inline Entity Forms. So they are being created via ajax. Could that be something?

  • πŸ‡ΊπŸ‡ΈUnited States duckydan

    I have a page where there are a bunch of ckeditor fields in paragraphs that all display at once. That works perfectly fine. So if they are all on the page to start with, the error does not occur.

  • πŸ‡ΊπŸ‡ΈUnited States duckydan
  • πŸ‡΅πŸ‡±Poland salmonek

    Thank you, we have reproduced the issue, and will notify you once we have it solved.

  • πŸ‡΅πŸ‡±Poland salmonek

    @duckydan

    I've posted MR with fix.
    We'll have internal QA on this issue however this may take some time (this week weekend in Poland starts on Wednesday).
    Feel free to test the solution, we'll be happy for any feedback.

  • Status changed to Needs review about 2 months ago
  • Status changed to RTBC about 2 months ago
  • πŸ‡ΊπŸ‡ΈUnited States duckydan

    Patch works perfectly!

    Thank you!

  • πŸ‡¨πŸ‡¦Canada endless_wander

    Thank you for this cool group of plugins. I was encountering a similar issue using just a single instance of CKEditor in combination with the Layout Paragraphs module.

    When adding a Paragraph via the Layout Paragraphs interface, CKEditor would not load. Console log gave same error as OP TypeError: null is not an object (evaluating 'this.wordCountWrapper.appendChild')

    Using merge request from #10 solves my issue as well.

  • Status changed to Fixed 12 days ago
  • πŸ‡΅πŸ‡±Poland dolszewski

    The latest release (1.1.0) contains a fix for that bug.

Production build 0.69.0 2024