Maxlength does not work with long, resource intensive forms

Created on 20 July 2023, 11 months ago
Updated 12 June 2024, 4 days ago

Problem/Motivation

A form that is long and is loading several different JavaScript files can lead to the MaxLength count not updating properly. This is because maxlength.js ends up being called before ckeditor5.js.

Steps to reproduce

Create a content type with many fields, to the point that different JavaScript files are being loaded. For example, create a form with many different Paragraph fields.

Proposed resolution

In 3.0.x this is mostly resolved because 3.x is now requiring ckeditor5/internal.drupal.ckeditor5 as a library dependency.

However, there is still a minor issue, which is that if the CKEditor 5 module is not installed you will get a warning message "The following theme is missing from the file system: ckeditor5" after installing MaxLength.

To resolve this we can use hook_library_info_alter to add the dependency just in case the CKEditor5 module is enabled.

Remaining tasks

  • ✅ Finalize steps to reproduce
  • ✅ Get maintainer approval for the proposed resolution
  • ❌ Implement resolution
  • ❌ Write test coverage (contact a maintainer if you need help)
  • ❌ Maintainer review via the UI
  • ❌ Maintainer Code Review #1
  • ❌ Maintainer code review #2
  • ❌ Merge into dev branch, with credit to author and participants

User interface changes

None

API changes

None

Data model changes

None

🐛 Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

🇮🇳India mahtab_alam

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

Merge Requests

Comments & Activities

  • Issue created by @mahtab_alam
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.5 + Environment: PHP 8.1 & MySQL 5.7
    last update 11 months ago
    4 pass, 1 fail
  • Status changed to Needs review 11 months ago
  • Status changed to Postponed: needs info 11 months ago
  • 🇺🇸United States cedewey Denver, CO

    Hi Mahtab,

    Thank you for reporting this issue and for working on a fix for it.

    I tried to recreate the issue with a vanilla Drupal 10.1.1 site, using the latest 2.1.x branch of MaxLength, Paragraphs 8.x-1.15 and CKEditor 5.

    It is all working as expected for me. I tested it with the hard limit option enabled and disabled. Both scenarios worked as expected.

    Please share more information on how to recreate this issue. Thanks!

  • 🇮🇳India mahtab_alam

    Can you try with paragraphs inside a paragraph scenario.
    You can also try using layout builder + paragraph approach.

  • Status changed to Closed: cannot reproduce 11 months ago
  • 🇺🇸United States cedewey Denver, CO

    I've tried nested paragraphs and having the content types use Layout Builder for the default view mode. Both scenarios work with MaxLength as expected. I'm going to mark this closed, cannot reproduce. If you still have an issue and can include specific steps to reproduce it, re-open it and we'll take another look.

  • 🇺🇸United States art4003 New York

    I am having the same issue here and the proposed solution by @mahtab_alam fixes the issue.

    My setup:
    - Content Type with Entity reference revisions field for Reference type: Paragraph.
    - Paragraph with long text field and MaxLength enabled.

  • Assigned to cedewey
  • Status changed to Needs review 7 months ago
  • 🇺🇸United States cedewey Denver, CO

    Re-opening this to see if I can reproduce the issue and to review the proposed fix.

  • 🇧🇷Brazil julio_retkwa

    Hi all

    I've faced the same issue and solution from @mahtab_alam worked fine, Thank you!
    had to do nothing else on maxlength.libraries.yml
    then just add:
    - ckeditor5/internal.drupal.ckeditor5

    In my scenario I was using paragraph

  • Pipeline finished with Skipped
    7 months ago
    #54946
  • First commit to issue fork.
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.5 + Environment: PHP 8.1 & MySQL 5.7
    last update 7 months ago
    4 pass, 1 fail
  • 🇩🇪Germany stefan.korn Jossgrund

    I can also confirm this issue in some setup. I believe it is not especially tied to CKeditor5 in paragraphs, because in my setup though we are using paragraphs the CKEditor5 field with max length setting is not used in a paragraph.

    I suppose it can happen that the maxlength.js is called before the ckeditor5.js and this is causing the issue, because the ckeditor5Id is not availabe for maxlength then: https://git.drupalcode.org/project/maxlength/-/blob/79379c927380d1796f38...

    Adding the dependency on ckeditor5/internal.drupal.ckeditor5 solves the issue by assuring that ckeditor5.js is always called before maxlength.js.
    This seems to be an easy solution for this problem, though it probaby is not nice for supporting CKEditor4 and would also request that library for non CKEditor fields with maxlength. A clean solution would need to distinguish whether we are on CKEditor5 field before attaching the library and then maybe have a library for ckeditor5 especially that has the dependency on ckeditor5/internal.drupal.ckeditor5. But this does not seem easy (the distinguishing part).

  • 🇩🇪Germany stefan.korn Jossgrund

    One thing I can think of, would be to introduce a new setting for maxlength like "require CKEditor5" and include the dependency only based on this setting.

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.5 + Environment: PHP 8.1 & MySQL 5.7
    last update 6 months ago
    6 pass
  • 🇩🇪Germany stefan.korn Jossgrund

    How about this patch, which introduces a new setting for CKEditor5 library dependency.

    Maybe could use allowed settings for this too and only allow on formatted text fields.

  • 🇧🇪Belgium joevagyok

    I don't like the idea to add a setting for the user to fix a problem which the user should not even be aware about and maintain that configuration setting, rather confusing.
    We need to find a solution which doesn't disrupt the user experience and doesn't require any action from the users.

  • 🇩🇪Germany stefan.korn Jossgrund

    We need to find a solution which doesn't disrupt the user experience and doesn't require any action from the users.

    true surely, but not so easy as far as I can see.

    For me now it is better to decide when to load the ckeditor5 library myself, rather than loading it just on any occasion which the previous patch does.

  • Issue was unassigned.
  • Status changed to Needs work 6 months ago
  • 🇺🇸United States cedewey Denver, CO

    I agree with joevagyok that we shouldn't introduce a setting for behavior the site builder expects by default.

    For version 3.0 we will 🌱 Remove CKEditor 4 support Active so that is worth taking into account with as we decide on the best solution.

    Also, can someone update the steps to reproduce? I'm still unclear on what specific scenario causes this problem, since some are reporting that it is not happening with Paragraphs.

  • 🇩🇪Germany stefan.korn Jossgrund

    I think it is a dependency issue which is rather hard to pin down. ckeditor5.js needs to be called before maxlength.js. This is not assured because maxlength does not set a dependency on this. Maybe if some other module is requiring maxlength, this may result in a change of the dependency order and maxlength.js comes before ckeditor5.js.

  • 🇩🇪Germany broon Potsdam

    I can confirm that adding the dependency by using a patch works and solves the problem.

    However as Stefan points out, it's not directly related to paragraphs but I believe rather depends on the size of the form which in turn may lead to different order of loading required JS files. I also agree that the user should not be required to switch on some extra option to make it work for each RTF field. But adding the dependency for all is also not correct as there might be sites not using CKEditor at all.

    Maybe, instead of having just a single library "maxlength", there ought to be additional ones like "maxlength_ckeditor" which should automatically be selected if the corresponding textfield is using CKEditor.

  • Assigned to joevagyok
  • 🇧🇪Belgium joevagyok

    Since we have reached Drupal 9 end of life there for CKEditor4 end of life as well which means there will be no further support or security releases for these versions, I think we will follow suit and focus on CKEditor5 and future release where we drop the support for CKEditor4.

  • 🇧🇪Belgium joevagyok

    This needs to be checked over 3.x-dev if it can be reproduced.

  • Environment: D10.2.3; PHP 8.2.15; MaxLength 3.0.0-beta1. This was a new installation of D10 last August. Added a new page (node) and reached a character limit and upon Save the Edit tab reloads without additional text. I tried increasing PHP memory from 128M to 256M and in Settings - not the problem I'm having but found and added the two lines with 2 changed to 6:
    /**
    * If you encounter a situation where users post a large amount of text, and
    * the result is stripped out upon viewing but can still be edited, Drupal's
    * output filter may not have sufficient memory to process it. If you
    * experience this issue, you may wish to uncomment the following two lines
    * and increase the limits of these variables. For more information, see
    * http://php.net/manual/pcre.configuration.php.
    */
    # ini_set('pcre.backtrack_limit', 200000);
    # ini_set('pcre.recursion_limit', 200000);

    ini_set('pcre.backtrack_limit', 600000);
    ini_set('pcre.recursion_limit', 600000);

    Neither of the above changes worked. I copied the text from edit window into Office doc. Character count is 3,031 and adding another sentence the change is not saved. So I installed MaxLength 3.0.0-beta1 and in /structure/types/manage/page/form-display I added and saved 10000 as the Body character limit. Adding an additional sentence with 6914 characters remaining, same result, Edit tab reloads with the additional sentence missing.

  • This module is working as intended. I added lorem ipsum text of almost 12,000 characters and the page saves.

    I found a new problem - the page has one external and one internal link. Adding an additional link causes the edit tab to reload and not save the change. Hmm?

    Sorry for the confusion.

  • Status changed to Postponed: needs info 4 months ago
  • Confirming that I was having this issue:

    - Version 2.1.2 of MaxLength module.
    - After upgrading to CKE5, the remaining character count was not updating on Paragraph content fields with the max length set (it was working in CKE4 on for those fields).
    - I updated to MaxLength 3.0.0-beta1 and the issue appears to be resolved.

  • 🇩🇪Germany stefan.korn Jossgrund

    3.x is now requiring ckeditor5/internal.drupal.ckeditor5 as a library dependency.

    Though this works as expected and fixes the issue mentioned here, it has a minor issue if ckeditor5 module is not installed.

    You will get warning message "The following theme is missing from the file system: ckeditor5" during installation of maxlength.

    This could be fixed by requiring ckeditor5 module in info.yml. But in a scenario where you do not want to use CKEditor5 at all, it seems not correct to force the installation of ckeditor5 module, because maxlength will in principle also work without it.

    So maybe one wants to tolerate the warning message during installation. Or one could maybe use hook_library_info_alter to add the dependency just in case ckeditor5 module is active.

  • Status changed to Needs work 3 months ago
  • 🇧🇪Belgium joevagyok

    Thanks for the feedback!

  • 🇺🇸United States cedewey Denver, CO

    Hi Stefan,

    Thank you for your ongoing testing and investigation of this issue!

    I support your proposal of using hook_library_info_alter to add the dependency in case the CKEditor5 module is enabled.

    Since this is now only displaying a warning message, I am reducing the priority to minor.

    I'll leave it assigned to joevagyok to review this suggested proposal and if you're up for it Joe, implement the proposed resolution.

  • 🇺🇸United States recrit

    Hiding patch 15 to avoid confusion. The MR should be used for any fixes.

  • 🇺🇸United States recrit

    attached a static patch of the current MR that can be used with 2.1.x for the library dependency change adding "ckeditor5/internal.drupal.ckeditor5" similar to 3.x.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.4 + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 month ago
    6 pass
  • 🇧🇪Belgium joevagyok

    joevagyok changed the visibility of the branch 3.x to hidden.

  • 🇧🇪Belgium joevagyok

    joevagyok changed the visibility of the branch 3375880-maxlength-does-not to hidden.

  • Status changed to Needs review about 1 month ago
  • 🇧🇪Belgium joevagyok

    Issue is fixed in a new PR, the merge commit will be pushed to 2.1.x as well.

  • Status changed to RTBC 18 days ago
  • Fix looks good. Can be merged if there no other objections.

  • Status changed to Fixed 18 days ago
    • joevagyok committed a41834a9 on 2.1.x
      Revert "Issue #3375880: Fix CKEditor5 library dependency."
      
      This reverts...
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024