Problem/Motivation

Testing html5 editor in a modal window throws "Uncaught TypeError: event.target.classList is undefined" in line 15 of core/modules/ckeditor5/js/ckeditor5.dialog.fix.js file.

Steps to reproduce

  • Open a modal with a ck5editor5 field inside.
  • switch to another window(i.e: CTRL+TAB) and return to the former window
  • The error is shown on console. (see attached file)

Note: debugging the case found that event.target variable is equal to an "HTMLDocument" object.
For @Anybody this happened in Firefox 112.0.2

Proposed resolution

Probably improving the condition that causes the error (i.e:
return event.target.classList && event.target.classList.contains('ck') || this._super(event);
)

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3351600

Command icon 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

gmateos created an issue. See original summary.

gmateos’s picture

Ranjit1032002 made their first commit to this issue’s fork.

ranjit1032002’s picture

Status: Active » Needs review
StatusFileSize
new639 bytes

Created a patch for the issue mentioned, please review.
Thank You.

ranjit1032002’s picture

StatusFileSize
new641 bytes

Fixed CCF, please review.

ranjit1032002’s picture

ranjit1032002’s picture

StatusFileSize
new671 bytes
new658 bytes

Fixed CCF, please review.
Attaching Interdiff.

ranjit1032002’s picture

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

andrew.farquharson made their first commit to this issue’s fork.

oily’s picture

StatusFileSize
new890.06 KB

I have tested patch #7. I forked the issue and created a new branch to apply the patch to and test it on. I installed the add_content_modal contrib module, used devel_generate to create some articles, configured the add_content_modal so i can edit the article content type in a modal.

See screenshot for the error message in the console and the ckeditor field loaded in a modal window. The error is 'Uncaught TypeError: event.data is undefined'.

anybody’s picture

The issue in #2 was created by me, so I can confirm I was running into this issue twice now.

Any ideas how it can come to this situation?

oily’s picture

Status: Needs work » Needs review

Hi @Anybody I think that if this is fixed the fix should work whether or not the admin_menu is enabled.

MR !3951 works for me repeating the test I describe at #11. No error messages in browser console when I switch focus between the ckeditor fields and another browser window.

@Anybody perhaps you could test MR !3951 with the admin menu enabled..

oily’s picture

Status: Needs review » Fixed
smustgrave’s picture

Status: Fixed » Needs work

Should only be marked fixed by a committer when the fix is merged.

But this was previously tagged for tests which still need to happen.

oily’s picture

@smustgrave Well, that may be correct. I understood that if i mark fixed it gets merged if there is no intervention for 2 weeks. This is not really a major issue. It generates an error in console but does not affect any functionality. CKeditor5 is 'experimental' in any case, is it not? Anyway let's hope others will test it. The term 'tests' is confusing. I mean this 'fix' just passed the automated tests. So can you define what you mean by 'tests'? If you mean the kind of 'tests' that are defined in the 'steps to reproduct' and that I define at #11, then great if numerous contributers test it. The more the better!

wim leers’s picture

In which browser is this happening?

anybody’s picture

Issue summary: View changes

For me it was Firefox

oily’s picture

@Wim Leers, I reproduced the error in Firefox 112.0.2. Also I tested my MR !3951 in the same and the error disappears. I switched focus between all of the fields in the node (inside a modal with ckeditor5 being used on the body field) and no errors triggered. The code change required is JQuery. I studied the JQuery documentation regarding the methods involved but the fix I got by googling how to fix 'Uncaught TypError undefined' error.

wim leers’s picture

Firefox twice.

Can you also try in another browser? That'd help to rule out a browser-specific bug as the cause.

oily’s picture

StatusFileSize
new622.03 KB

The screenshot shows a different? error triggered in Safari Version 16.2.

oily’s picture

StatusFileSize
new843.69 KB

#24

oily’s picture

StatusFileSize
new885.83 KB

Merge request !3951 tested in Chrome version 112.0

oily’s picture

StatusFileSize
new552.34 KB

Merge request !3951 tested in Safari 16.2

oily’s picture

Status: Needs work » Needs review
oily’s picture

StatusFileSize
new545.13 KB

Merge request !3951 tested in Firefox 113.0

oily’s picture

If you can use DDEV-LOCAL, here are most of the command line steps I used after cloning the repository, forking the issue and checking out the branch:

DDEV steps to reproduce

ddev config --project-type=drupal10
ddev start
ddev composer install
ddev composer require drush/drush
ddev drush site:install --account-name=admin --account-pass=admin -y
ddev launch
ddev composer require 'drupal/add_content_modal:^1.0'
ddev drush en add_content_modal
ddev composer require 'drupal/devel:^5.0'
ddev drush generate-content 20
ddev drush cr

You will have to go to disable aggregation of css and js, clear all caches
Configure the add_content_modal: enable it for at least one content type

Then when editing one of the generated basic pages or articles, it should open in a modal (make sure you have configured this in add_content_modal settings. Then make sure that e.g. the body field of the content type is configured to use ckeditor5. Then move cursor focus between the various fields of the node edit form in the modal. Then click on another browser tab and return. Inspect using browser tools, selecting the 'console' tab. Make sure error are displayed in the console. Repeat in different browsers.

oily’s picture

Status: Needs review » Needs work
oily’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

Did not see tests in the MR

oily’s picture

@smustgrave

This is one example core test that seems to cover everything I could possibly create a test for:

core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5Test.php

It not only creates a text field for a node and activates ckeditor5 for that field, it inserts text into the text field using every possible button in the toolbar of the ckeditor and saves the result..

And it is one of 20 'FunctionalJavascript' tests. I am assuming that all these tests are run when anyone runs automated testing? Are you expecting in addition to all such tests me to write a custom one? If so, what do i need to test that is not being tested already? Or are these core tests not triggered when choosing 'Add test / re-test'?

If they are triggered then for overall functionality of the ckeditor5 module then these tests seem comprehensive. The error I am trying to fix though triggering an error does not seem to break any functionality so by in addition, manually viewing the browser's console, i would expect the combined test coverage to be as complete as it ever could be?

smustgrave’s picture

Probably would leave up to submaintainer and committer if they would merge without test coverage but it is possible to test for console errors. There may be a FunctionalJavascript function for this or it could be nightwatch. Would have to double check that.

oily’s picture

@smustgrave Yes I need to re-read the original description of this issue. I can install the add_content_modal:^1.0 module, make it a test dependency. I will also have a look at nightwatch- see if it can supply any testing needs.

smustgrave’s picture

Also posted in the slack channel for wimleers to take a look.

oily’s picture

@smustgrave, thank you for posting in Slack. There are indeed assertions in Nightwatch that test browser tools console output.

wim leers’s picture

Status: Needs work » Postponed (maintainer needs more info)

Could you also try to reproduce this error in Chrome please? 🙏

Drupal's automated JavaScript tests use Chrome. If we can reproduce it in Chrome, an automated test is possible. Otherwise, it's impossible.

Great work here so far BTW! 👏😊

oily’s picture

@Wim Leers The error does not appear in Chrome. I see that the nightwatch.conf.js file in core only sets up a chrome environment. But not currently Firefox or Safari. To test the error using Nightwatch I would have to add an environment for these other browsers.

@smustgrave Is that something that is permissible? Or is the core nightwatch config restricted to Chrome only? If Chrome only then it seems as @Wim Leers says creatoin of an automated test for this issue is not possible.

wim leers’s picture

Status: Postponed (maintainer needs more info) » Reviewed & tested by the community
Issue tags: -Needs tests, -Needs steps to reproduce +JavaScript, +Needs frontend framework manager review

Alright, it's not possible to test then 👍

The fix seems reasonable.

anybody’s picture

Issue tags: -JavaScript +JavaScript

Very much looking forward to the fix in 10.1.x. Will this be part of the next minor release (possibly 10.1.1?) Current broken state of WYSIWYG editor functionality in 10.1.0 is a real issue for editors.

Changing the priority to major would be sufficient in this case, I guess, due to the broken key functionalities, like linking content (through Linkit) but won't change anything here. So I'll leave it as is and just say THANK YOU ALL for fixing this :)

anybody’s picture

As the MR patch doesn't apply against 10.1.0 I guess this will needs rerolls against 10.1.x and 11.x?
Should we do that in separate MR's or how to proceed here best @Wim Leers?

Or will this be first committed against 10.0.x now?

catch’s picture

Version: 10.0.x-dev » 11.x-dev
Status: Reviewed & tested by the community » Needs work

The MR diff applies against 11.x for me, however I think this needs an inline comment.

oily’s picture

Hi @catch I have added comments.

 // Fixes a console error message generated in Firefox only
 // @see https://www.drupal.org/project/drupal/issues/3351600

I can edit them if they are not clear enough.

anybody’s picture

Title: ckeditor5.dialog.fix.js throw "Uncaught TypeError: event.target.classList is undefined" in Drupal 10 with the editor in a modal » ckeditor5.dialog.fix.js throws "Uncaught TypeError: event.target.classList is undefined" in Firefox in Drupal 10 with the editor in a modal

I think we need the MR to be against 11.x, but I can't change that. Comment was added. @catch for help? ;)

anybody’s picture

Uploading the static patch from MR!3951, if anyone needs it for composer and confirming it still applies and works with Drupal 10.1.1 and Drupal 11.

So re-confirming RTBC from #39 once this is rebased / retargeted.

jiong_ye’s picture

StatusFileSize
new517 bytes

Running into the same issue with 9.5

ant1’s picture

#45 still works in Drupal 10.1.4.
I will not change the Status, as I don't know if it has been rebased / retargeted.

sanduhrs made their first commit to this issue’s fork.

sanduhrs’s picture

Status: Needs work » Reviewed & tested by the community

New merge request against 11.x, back to RTBC :)

  • lauriii committed 8b0a91f6 on 11.x
    Issue #3351600 by andrew.farquharson, Ranjit1032002, Anybody, sanduhrs,...

  • lauriii committed 440897fd on 10.2.x
    Issue #3351600 by andrew.farquharson, Ranjit1032002, Anybody, sanduhrs,...

  • lauriii committed 42ab3f2e on 10.1.x
    Issue #3351600 by andrew.farquharson, Ranjit1032002, Anybody, sanduhrs,...
lauriii’s picture

Version: 11.x-dev » 10.1.x-dev
Status: Reviewed & tested by the community » Fixed
Issue tags: -Needs frontend framework manager review

I don't think this needs a frontend framework manager review. This is a straight forward bug fix targeting a specific browser that we don't have as part of our testing infrastructure.

Committed 8b0a91f and pushed to 11.x. Also cherry-picked to 10.2.x and 10.1.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

nicocin’s picture

Issue summary: View changes
StatusFileSize
new987 bytes

It seems that the patch #46 does not writes to the proper place. This one should work well.

rodrigoaguilera’s picture

StatusFileSize
new809 bytes

The above patch did not apply to 9.5.11 installation.

Attached a new version without code changes