Skip to content

Commit 03832d6

Browse files
authored
fix: support react18 strict mode (#85)
1 parent 74f8ee5 commit 03832d6

File tree

5 files changed

+89
-475
lines changed

5 files changed

+89
-475
lines changed

demo/Playground.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ logger.setLogger({
4343
...console,
4444
});
4545

46-
export const Playground = React.memo<PlaygroundProps>((props) => {
46+
const Playground = React.memo<PlaygroundProps>((props) => {
4747
const {initial, allowHTML, breaks, linkify, linkifyTlds} = props;
4848
const [previewType, setPreviewType] = React.useState<string>(PreviewType.Markup);
4949
const [yfmRaw, setYfmRaw] = React.useState<MarkupString>(initial || '');
@@ -199,9 +199,17 @@ export const Playground = React.memo<PlaygroundProps>((props) => {
199199
</div>
200200
);
201201
});
202-
203202
Playground.displayName = 'Playground';
204203

204+
const PlaygroundStrict: React.FC<PlaygroundProps> = (props) => (
205+
<React.StrictMode>
206+
<Playground {...props} />
207+
</React.StrictMode>
208+
);
209+
PlaygroundStrict.displayName = 'PlaygroundStrict';
210+
211+
export {PlaygroundStrict as Playground};
212+
205213
// const fileUploadHandler: FileUploadHandler = async (file) => {
206214
// console.info('[Playground] Uploading file: ' + file.name);
207215
// await randomDelay(1000, 3000);

demo/ProseMirrorDevTools.tsx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
1-
import React from 'react';
2-
import ReactDOM from 'react-dom';
1+
import {useEffect} from 'react';
32
import type {EditorView} from 'prosemirror-view';
4-
import applyDevTools from 'prosemirror-dev-tools';
5-
6-
const DEVTOOLS_CLASS_NAME = '__prosemirror-dev-tools__';
3+
import {applyDevTools, removeDevTools} from 'prosemirror-dev-toolkit';
74

85
export type ProseMirrorDevToolsProps = {
96
view: EditorView;
107
};
118

129
export function ProseMirrorDevTools({view}: ProseMirrorDevToolsProps) {
13-
React.useEffect(() => {
10+
useEffect(() => {
1411
applyDevTools(view);
15-
}, [view]);
16-
React.useLayoutEffect(() => {
1712
return () => {
18-
const devToolsRoot = document.querySelector(`.${DEVTOOLS_CLASS_NAME}`);
19-
if (devToolsRoot) ReactDOM.unmountComponentAtNode(devToolsRoot);
13+
removeDevTools();
2014
};
2115
}, [view]);
22-
2316
return null;
2417
}

0 commit comments

Comments
 (0)