TINY-12536: Loader catches and reports errors from tinymce.init (#10473)

This commit is contained in:
James Johnson
2025-07-18 12:15:03 +10:00
committed by GitHub
parent 618c517059
commit b7a0e50b92
2 changed files with 35 additions and 25 deletions

View File

@ -0,0 +1,6 @@
project: mcagar
kind: Fixed
body: Loader will catch errors thrown by `tinymce.init` and report them to the caller.
time: 2025-07-16T14:36:55.407731349+10:00
custom:
Issue: TINY-12536

View File

@ -1,5 +1,5 @@
import { TestLogs } from '@ephox/agar';
import { Arr, Fun, FutureResult, Global, Id, Optional, Result } from '@ephox/katamari';
import { Arr, Fun, FutureResult, Global, Id, Optional, Result, Type } from '@ephox/katamari';
import { Attribute, DomEvent, Insert, Remove, SelectorFilter, SugarBody, SugarElement, SugarHead, SugarShadowDom } from '@ephox/sugar';
import { Editor } from '../alien/EditorTypes';
@ -74,7 +74,8 @@ const setup = (callbacks: Callbacks, settings: Record<string, any>, elementOpt:
};
// Agar v. ??? supports logging
const onFailure = (err: Error | string, logs?: TestLogs) => {
const onFailure = (errU: unknown, logs?: TestLogs) => {
const err = Type.isString(errU) || errU instanceof Error ? errU : String(errU);
// eslint-disable-next-line no-console
console.log('Tiny Loader error: ', err);
// Do no teardown so that the failed test still shows the editor. Important for selection
@ -88,31 +89,34 @@ const setup = (callbacks: Callbacks, settings: Record<string, any>, elementOpt:
callbacks.preInit(tinymce, settings);
const targetSettings = SugarShadowDom.isInShadowRoot(target) ? ({ target: target.dom }) : ({ selector: '#' + randomId });
try {
Promise.resolve(tinymce.init({
promotion: false,
license_key: 'gpl',
...settings,
...targetSettings,
setup: (editor: Editor) => {
// Execute the setup called by the test.
settingsSetup(editor);
tinymce.init({
promotion: false,
license_key: 'gpl',
...settings,
...targetSettings,
setup: (editor: Editor) => {
// Execute the setup called by the test.
settingsSetup(editor);
editor.once('SkinLoaded', () => {
setTimeout(() => {
try {
callbacks.run(editor, onSuccess, onFailure);
} catch (e: any) {
onFailure(e);
}
}, 100);
});
editor.once('SkinLoaded', () => {
setTimeout(() => {
try {
callbacks.run(editor, onSuccess, onFailure);
} catch (e: any) {
onFailure(e);
}
}, 100);
});
editor.once('SkinLoadError', (e) => {
callbacks.failure(e.message);
});
}
});
editor.once('SkinLoadError', (e) => {
callbacks.failure(e.message);
});
}
})).catch(onFailure);
} catch (err: unknown) {
onFailure(err);
}
};
if (!Global.tinymce) {