Merge pull request #590 from ONLYOFFICE/feature/optimization-editor

Doceditor: add loaded scripts with bundle
This commit is contained in:
Alexey Safronov 2024-08-19 19:50:35 +04:00 committed by GitHub
commit 195c008b12
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 8 deletions

View File

@ -24,16 +24,17 @@
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
import type { Metadata } from "next";
import { headers } from "next/headers";
import Script from "next/script";
import { getSelectorsByUserAgent } from "react-device-detect";
import { ValidationStatus } from "@docspace/shared/enums";
import { getData, validatePublicRoomKey } from "@/utils/actions";
import { RootPageProps } from "@/types";
import Root from "@/components/Root";
import FilePassword from "@/components/file-password";
import { ValidationStatus } from "@docspace/shared/enums";
const initialSearchParams: RootPageProps["searchParams"] = {
fileId: undefined,
@ -71,8 +72,6 @@ async function Page({ searchParams }: RootPageProps) {
}
}
const startDate = new Date();
const data = await getData(
fileId ?? fileid ?? "",
version,
@ -82,13 +81,22 @@ async function Page({ searchParams }: RootPageProps) {
type,
);
const timer = new Date().getTime() - startDate.getTime();
if (data.error?.status === "not-found" && error) {
data.error.message = error;
}
return <Root {...data} timer={timer} />;
let url = data.config?.editorUrl ?? data.error?.editorUrl;
if (url && !url.endsWith("/")) url += "/";
const docApiUrl = `${url}web-apps/apps/api/documents/api.js`;
return (
<>
<Root {...data} />
<Script id="editor-api" strategy="beforeInteractive" src={docApiUrl} />
</>
);
}
export default Page;

View File

@ -24,6 +24,8 @@
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
/* eslint-disable @next/next/no-before-interactive-script-outside-document */
import Script from "next/script";
import runtime from "../../../runtime.json";
@ -35,9 +37,11 @@ const Scripts = () => {
<>
<Script
id="browser-detector"
strategy="beforeInteractive"
src={`/static/scripts/browserDetector.js?hash=${runtime?.checksums?.["browserDetector.js"] ?? hashDate}`}
/>
<Script id="portal-config">
<Script id="portal-config" strategy="beforeInteractive">
{`
console.log("It's DocEditor INIT");
fetch("/static/scripts/config.json?hash=${runtime?.checksums["config.json"] ?? hashDate}")