Skip to content

Commit b1f435a

Browse files
committed
INT-3336: Replace deprecated APIs and manually fix syntax errors
1 parent cde9356 commit b1f435a

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

src/main/ts/components/Editor.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export class Editor extends React.Component<IAllProps> {
145145
public editor?: TinyMCEEditor;
146146

147147
private id: string;
148-
private elementRef: React.RefObject<HTMLElement>;
148+
private elementRef: React.RefObject<HTMLElement | null>;
149149
private inline: boolean;
150150
private currentContent?: string;
151151
private boundHandlers: Record<string, (event: EditorEvent<unknown>) => unknown>;
@@ -155,7 +155,7 @@ export class Editor extends React.Component<IAllProps> {
155155
public constructor(props: Partial<IAllProps>) {
156156
super(props);
157157
this.id = this.props.id || uuid('tiny-react');
158-
this.elementRef = React.createRef<HTMLElement>();
158+
this.elementRef = React.createRef<HTMLElement | null>();
159159
this.inline = this.props.inline ?? this.props.init?.inline ?? false;
160160
this.boundHandlers = {};
161161
}

src/test/ts/alien/Loader.tsx

Lines changed: 17 additions & 15 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 ReactDOM from 'react-dom';
54
import { Editor, IAllProps, IProps, Version } from '../../../main/ts/components/Editor';
65
import { Editor as TinyMCEEditor } from 'tinymce';
76
import { before, context } from '@ephox/bedrock-client';
87
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,6 +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);
3637

3738
const ctx = await new Promise<Context>((resolve, reject) => {
3839
const init: IProps['init'] = {
@@ -43,18 +44,18 @@ export const render = async (props: Partial<IAllProps> = {}, container: HTMLElem
4344
editor.on('SkinLoaded', () => {
4445
setTimeout(() => {
4546
Optional.from(ref.current)
46-
.map(ReactDOM.findDOMNode)
47-
.bind(Optional.from)
47+
.map((editorInstance) => editorInstance.editor?.targetElm as HTMLElement)
4848
.map(SugarElement.fromDom)
4949
.filter(SugarNode.isHTMLElement)
5050
.map((val) => val.dom)
51-
.fold(() => reject('Could not find DOMNode'), (DOMNode) => {
52-
resolve({
53-
ref,
54-
editor,
55-
DOMNode,
56-
});
57-
});
51+
.fold(() =>
52+
reject('Could not find editor element'),
53+
(DOMNode) => resolve({
54+
ref: ref as React.RefObject<Editor>,
55+
editor,
56+
DOMNode
57+
})
58+
);
5859
}, 0);
5960
});
6061
}
@@ -67,19 +68,20 @@ export const render = async (props: Partial<IAllProps> = {}, container: HTMLElem
6768
* touch the nodes created by TinyMCE. Since this only seems to be an issue when rendering TinyMCE 4 directly
6869
* into a root and a fix would be a breaking change, let's just wrap the editor in a <div> here for now.
6970
*/
70-
ReactDOM.render(<div><Editor ref={ref} apiKey='no-api-key' {...props} init={init} /></div>, container);
71+
root.render(<div><Editor ref={ref} apiKey='no-api-key' {...props} init={init} /></div>);
7172
});
7273

7374
const remove = () => {
74-
ReactDOM.unmountComponentAtNode(container);
75+
root.unmount();
7576
};
7677

7778
return {
7879
...ctx,
7980
/** By rendering the Editor into the same root, React will perform a diff and update. */
80-
reRender: (newProps: IAllProps) => new Promise<void>((resolve) =>
81-
ReactDOM.render(<div><Editor apiKey='no-api-key' ref={ctx.ref} {...newProps} /></div>, container, resolve)
82-
),
81+
reRender: (newProps: IAllProps) => new Promise<void>((resolve) => {
82+
root.render(<div><Editor apiKey='no-api-key' ref={ctx.ref} {...newProps} /></div>);
83+
resolve();
84+
}),
8385
remove,
8486
[Symbol.dispose]: remove
8587
};

0 commit comments

Comments
 (0)