Skip to content

Commit

Permalink
#4981 - removing the mount check
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Vialov committed Jul 29, 2024
1 parent 3dd35eb commit bbcf1f4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 103 deletions.
2 changes: 1 addition & 1 deletion example-ssr/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
// reactStrictMode: true,
};

export default nextConfig;
17 changes: 8 additions & 9 deletions example-ssr/src/app/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,19 @@ export function EditorComponent() {
<Editor
staticResourcesUrl={process.env.PUBLIC_URL || ''}
structServiceProvider={structServiceProvider}
ssr={false}
errorHandler={(message: string) => {
console.error(message);
}}
onInit={(ketcher) => {
if (window) {
window.ketcher = ketcher;
window.ketcher = ketcher;

window.parent.postMessage(
{
eventType: 'init',
},
'*',
);
}
window.parent.postMessage(
{
eventType: 'init',
},
'*',
);
}}
/>
);
Expand Down
72 changes: 0 additions & 72 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 2 additions & 21 deletions packages/ketcher-react/src/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import 'whatwg-fetch';
import './index.less';

import init, { Config } from './script';
import { useEffect, useRef, useState } from 'react';
import { useEffect, useRef } from 'react';
import { createRoot, Root } from 'react-dom/client';

import { Ketcher } from 'ketcher-core';
Expand All @@ -41,10 +41,9 @@ const mediaSizes = {

interface EditorProps extends Omit<Config, 'element' | 'appRoot'> {
onInit?: (ketcher: Ketcher) => void;
ssr?: boolean;
}

function EditorComponent(props: EditorProps) {
function Editor(props: EditorProps) {
const initPromiseRef = useRef<ReturnType<typeof init> | null>(null);
const appRootRef = useRef<Root | null>(null);
const cleanupRef = useRef<(() => unknown) | null>(null);
Expand Down Expand Up @@ -104,22 +103,4 @@ function EditorComponent(props: EditorProps) {
);
}

function EditorSsr(props: EditorProps) {
const [hasMounted, setHasMounted] = useState(false);

useEffect(() => {
setHasMounted(true);
}, []);

if (!hasMounted) {
return null;
}

return <EditorComponent {...props} />;
}

function Editor(props: EditorProps) {
return props.ssr ? <EditorSsr {...props} /> : <EditorComponent {...props} />;
}

export { Editor };

0 comments on commit bbcf1f4

Please sign in to comment.