Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

specialchar plugin overwrites translation data when opening the dialog causing crash if multiple richtext areas are created after opening the first dialog #5485

Open
nchieffo opened this issue May 23, 2023 · 11 comments
Labels
plugin:specialchar The plugin which probably causes the issue. status:confirmed An issue confirmed by the development team. type:bug A bug.

Comments

@nchieffo
Copy link

Type of report

Bug

Provide detailed reproduction steps (if any)

When the user runs the specialchar command, the code executes a call to a function that loads a 2nd localization file in dialogs/lang/ folder.
That file contains a script that executes this function
CKEDITOR.plugins.setLang( 'specialchar', 'en', {

Expected result

The code that is executed in the translation file DOES NOT overwrite the plugin translation data that is stored in CKEDITOR.plugins.registered.specialchar.langEntries

Actual result

The code that is executed in the translation file overwrite the plugin translation data that is stored in CKEDITOR.plugins.registered.specialchar.langEntries

Other details

Normally when using 1 single CKEditor window, the problem is not visible, as the translations are actually extended in the local editor variable, as part of the script load callback.
CKEDITOR.tools.extend( editor.lang.specialchar, plugin.langEntries[ langCode ] );
But at this point the shared translations have been overwritten with the new localization loaded

In the software that I'm using (Coremedia CMS with ckeditor 4.19), multiple CKEditor windows can coexist, and the CKEDITOR variable is shared.
When opening a CMS content with a richtext editor for the first time, and opening the specialchar dialog, everything is fine.
But when opening a second CMS content with a richtext editor, a the CKEDITOR variable is re-used, the plugin is not re-loaded as it's already loaded but it contains the wrong translations, so when the dialog is being created, the lang.title variable is null, causing the plugin to crash.
in specialchar.js

	return {
		title: lang.title,

CKEDITOR crashes because of undefined title variable in the dialog

I have found a way to fix it, by adding an additional invocation in plugin.js

CKEDITOR.scriptLoader.load( CKEDITOR.getUrl( plugin.path + 'dialogs/lang/' + langCode + '.js' ), function() {
	CKEDITOR.tools.extend( editor.lang.specialchar, plugin.langEntries[ langCode ] );
	CKEDITOR.plugins.setLang( 'specialchar', langCode, editor.lang.specialchar); // this is the line I added
	editor.openDialog( pluginName );
} );
@nchieffo nchieffo added the type:bug A bug. label May 23, 2023
@github-actions
Copy link

It's been a while since we last heard from you. We are marking this issue as stale due to inactivity. Please provide the requested feedback or the issue will be closed after next 7 days.

@github-actions github-actions bot added the stale The issue / PR will be closed within the next 7 days of inactivity. label May 31, 2023
@nchieffo
Copy link
Author

Why? I was not asked any additional question

@github-actions github-actions bot removed the stale The issue / PR will be closed within the next 7 days of inactivity. label Jun 1, 2023
@Comandeer
Copy link
Member

@nchieffo, I'd like to apologize for the delay in responding.

Could you show a simple reproduction of the issue, e.g. on CodePen? It would greatly help with debugging the issue.

@nchieffo
Copy link
Author

nchieffo commented Jun 9, 2023

Sorry but I'm not that experienced with ckeditor, I was just using it through a CMS and I don't know how the instantiations are done.
I will summarize the flow that may be problematic:
STEP 0

  • CKEDITOR variable is initialized

STEP 1

  1. editor widget is loaded in a page div
  2. specialchar plugin is loaded
  3. base specialchar translations are loaded
  4. dialogs/lang/ specialchar translations are loaded
  5. base specialchar translations are lost because the dialogs/lang script invokes CKEDITOR.plugins.setLang( 'specialchar', 'en',

STEP 2

  • another editor widget is loaded in another page div
  • specialchar plugin was already loaded, so it is NOT loaded again
  • at this point the code fails because even if specialchar plugin was already loaded, it misses the default translations that have been overwritten at step 5. before

@Comandeer
Copy link
Member

@nchieffo, I'm not able to reproduce the issue → https://jsfiddle.net/Comandeer/ofw17b3j/

The demo shows two editor instances with specialchar plugin, even with different languages, but everything still works fine.

@nchieffo
Copy link
Author

Thanks for creating the demo, I'll try to have a look and make it reproducible

@nchieffo
Copy link
Author

I started to make some changes, and here's where I was able to do, still incomplete : https://jsfiddle.net/b3d0rezy/2/

The key difference that I'm not able to replicate, is that the plugin is not bundled in the JS, and is not initialized in the config object, but it's initialized afterwards by picking an external .js file called specialchar/plugin.js

CKEDITOR.plugins.addExternal("specialchar", "/resources/com.coremedia.blueprint__vfcorp-studio-plugin/ckeditor/plugins/specialchar/plugin.js", "")

I'm unable to find this file in a public CDN so I can't try to have it in jsfiddle

@Comandeer Comandeer added status:confirmed An issue confirmed by the development team. plugin:specialchar The plugin which probably causes the issue. labels Jun 19, 2023
@Comandeer
Copy link
Member

I've finally managed to reproduce the issue: https://jsfiddle.net/Comandeer/7rhwq8Ld/

Procedure:

  1. Open the "Special Characters" dialog in the first editor.
  2. Close it and press the "CREATE EDITOR 2" button.
  3. Press the "Special Characters" button in the second editor

The actual result:

Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.
    at CKEDITOR.dom.element.append (ckeditor.js:101:300)
    at CKEDITOR.dom.text.appendTo (ckeditor.js:76:77)
    at new CKEDITOR.dialog (ckeditor.js:646:270)
    at a.openDialog (ckeditor.js:689:134)
    at Object.<anonymous> (plugin.js?t=N2M9:36:13)
    at x (ckeditor.js:261:181)
    at y (ckeditor.js:261:336)
    at F (ckeditor.js:261:449)
    at Object.load (ckeditor.js:263:29)
    at CKEDITOR.command.exec (plugin.js?t=N2M9:34:27) 

@nchieffo
Copy link
Author

@Comandeer thank you very much for your help. Do you think that the solution provided in the 1st post may be valid?

@Comandeer
Copy link
Member

Yes, it seems so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin:specialchar The plugin which probably causes the issue. status:confirmed An issue confirmed by the development team. type:bug A bug.
Projects
None yet
Development

No branches or pull requests

4 participants
@nchieffo @Comandeer and others