Skip to content

Commit d5432fe

Browse files
committed
INT-3336: Avoid casting the editor targetElm
1 parent 6d36958 commit d5432fe

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/test/ts/alien/Loader.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { Fun, Optional } from '@ephox/katamari';
22
import { SugarElement, SugarNode } from '@ephox/sugar';
33
import * as React from 'react';
4+
import * as ReactDOMClient from 'react-dom/client';
45
import { Editor, IAllProps, IProps, Version } from '../../../main/ts/components/Editor';
56
import { Editor as TinyMCEEditor } from 'tinymce';
67
import { before, context } from '@ephox/bedrock-client';
78
import { VersionLoader } from '@tinymce/miniature';
8-
import { createRoot } from 'react-dom/client';
99

1010
// @ts-expect-error Remove when dispose polyfill is not needed
1111
Symbol.dispose ??= Symbol('Symbol.dispose');
@@ -33,7 +33,7 @@ export const render = async (props: Partial<IAllProps> = {}, container: HTMLElem
3333
const originalInit = props.init || {};
3434
const originalSetup = originalInit.setup || Fun.noop;
3535
const ref = React.createRef<Editor>();
36-
const root = createRoot(container);
36+
const root = ReactDOMClient.createRoot(container);
3737

3838
const ctx = await new Promise<Context>((resolve, reject) => {
3939
const init: IProps['init'] = {
@@ -44,17 +44,18 @@ export const render = async (props: Partial<IAllProps> = {}, container: HTMLElem
4444
editor.on('SkinLoaded', () => {
4545
setTimeout(() => {
4646
Optional.from(ref.current)
47-
.map((editorInstance) => editorInstance.editor?.targetElm as HTMLElement)
47+
.bind((editorInstance) => Optional.from(editorInstance.editor?.targetElm))
48+
.filter((elm) => elm instanceof window.HTMLElement)
4849
.map(SugarElement.fromDom)
4950
.filter(SugarNode.isHTMLElement)
5051
.map((val) => val.dom)
51-
.fold(() =>
52-
reject('Could not find editor element'),
53-
(DOMNode) => resolve({
54-
ref: ref as React.RefObject<Editor>,
55-
editor,
56-
DOMNode
57-
})
52+
.fold(() => reject('Could not find DOMNode'), (DOMNode) => {
53+
resolve({
54+
ref: ref as React.RefObject<Editor>,
55+
editor,
56+
DOMNode,
57+
});
58+
}
5859
);
5960
}, 0);
6061
});

0 commit comments

Comments
 (0)