Merge pull request #757 from ONLYOFFICE/bugfix/editor-ssr-fix
Bugfix/editor ssr fix
This commit is contained in:
commit
296959b9ea
@ -11,14 +11,9 @@ import fs from "fs";
|
||||
import logger from "morgan";
|
||||
import winston from "./lib/logger.js";
|
||||
import { getAssets, initDocEditor } from "./lib/helpers";
|
||||
import GlobalStyle from "../client/components/GlobalStyle.js";
|
||||
import { I18nextProvider } from "react-i18next";
|
||||
import React from "react";
|
||||
import { renderToString } from "react-dom/server";
|
||||
import Editor from "../client/components/Editor.js";
|
||||
import { ServerStyleSheet } from "styled-components";
|
||||
import renderApp from "./lib/helpers/render-app";
|
||||
|
||||
const sheet = new ServerStyleSheet();
|
||||
//const sheet = new ServerStyleSheet();
|
||||
const fallbackLng = "en";
|
||||
|
||||
let port = PORT;
|
||||
@ -29,16 +24,6 @@ const parsedCOnfig = JSON.parse(config);
|
||||
if (parsedCOnfig?.PORT) {
|
||||
port = parsedCOnfig.PORT;
|
||||
}
|
||||
const renderApp = (i18n, initialEditorState) => {
|
||||
return renderToString(
|
||||
sheet.collectStyles(
|
||||
<I18nextProvider i18n={i18n}>
|
||||
<GlobalStyle />
|
||||
<Editor {...initialEditorState} />
|
||||
</I18nextProvider>
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
winston.stream = {
|
||||
write: (message) => winston.info(message),
|
||||
@ -102,12 +87,11 @@ if (IS_DEVELOPMENT) {
|
||||
winston.error(initialEditorState.error.errorMessage);
|
||||
}
|
||||
|
||||
const appComponent = renderApp(i18n, initialEditorState);
|
||||
const styleTags = sheet.getStyleTags();
|
||||
const { component, styleTags } = renderApp(i18n, initialEditorState);
|
||||
|
||||
const htmlString = template(
|
||||
initialEditorState,
|
||||
appComponent,
|
||||
component,
|
||||
styleTags,
|
||||
initialI18nStoreASC,
|
||||
userLng,
|
||||
|
24
packages/editor/src/server/lib/helpers/render-app.jsx
Normal file
24
packages/editor/src/server/lib/helpers/render-app.jsx
Normal file
@ -0,0 +1,24 @@
|
||||
import React from "react";
|
||||
import { ServerStyleSheet } from "styled-components";
|
||||
import GlobalStyle from "../../../client/components/GlobalStyle";
|
||||
import Editor from "../../../client/components/Editor";
|
||||
import { renderToString } from "react-dom/server";
|
||||
import { I18nextProvider } from "react-i18next";
|
||||
|
||||
const renderApp = (i18n, initialState) => {
|
||||
const sheet = new ServerStyleSheet();
|
||||
const component = renderToString(
|
||||
sheet.collectStyles(
|
||||
<I18nextProvider i18n={i18n}>
|
||||
<GlobalStyle />
|
||||
<Editor {...initialState} />
|
||||
</I18nextProvider>
|
||||
)
|
||||
);
|
||||
|
||||
const styleTags = sheet.getStyleTags();
|
||||
|
||||
return { component, styleTags };
|
||||
};
|
||||
|
||||
export default renderApp;
|
Loading…
Reference in New Issue
Block a user