diff --git a/frontend/app/root.tsx b/frontend/app/root.tsx index 5e36843..d5af255 100644 --- a/frontend/app/root.tsx +++ b/frontend/app/root.tsx @@ -9,6 +9,11 @@ import { import type { Route } from "./+types/root"; import { AuthProvider } from "./context/AuthContext"; +// Monaco 离线加载配置:必须在任何 挂载前执行,否则 loader 会默认 +// 从 jsDelivr CDN 拉取 monaco,离线环境下编辑器初始化失败、永远 loading。 +// `.client` 后缀:该模块只进客户端 bundle,SPA 构建的 server 预渲染阶段 +// 会被替换成空桩,避免 monaco-editor ESM(依赖浏览器全局)在 Node 里崩掉。 +import "./lib/monacoSetup.client"; import "./app.css"; export const links: Route.LinksFunction = () => []; diff --git a/frontend/package.json b/frontend/package.json index 6ff0f4f..7e91070 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -10,6 +10,7 @@ }, "dependencies": { "@monaco-editor/react": "^4.7.0", + "monaco-editor": "^0.56.0", "@react-router/node": "^8", "@react-router/serve": "^8", "isbot": "^5.1.36", diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yaml index 3ae96bc..ceb621b 100644 --- a/frontend/pnpm-lock.yaml +++ b/frontend/pnpm-lock.yaml @@ -20,6 +20,9 @@ importers: isbot: specifier: ^5.1.36 version: 5.2.1 + monaco-editor: + specifier: ^0.56.0 + version: 0.56.0 react: specifier: ^19.2.7 version: 19.2.8 @@ -47,7 +50,7 @@ importers: version: 19.2.17 '@types/react-dom': specifier: ^19.2.3 - version: 19.2.3(@types/react@19.2.17) + version: 19.2.4(@types/react@19.2.17) tailwindcss: specifier: ^4.2.2 version: 4.3.3 @@ -504,8 +507,8 @@ packages: '@types/node@22.20.1': resolution: {integrity: sha512-EANqOCF9QFyra+4pfxUcX9STKJpCLjMbObVzljIJomAWSnuSIEAvyzEU53GaajbXJEgdh0iEcPL+DGvpUd4k1Q==} - '@types/react-dom@19.2.3': - resolution: {integrity: sha512-jp2L/eY6fn+KgVVQAOqYItbF0VY/YApe5Mz2F0aykSO8gx31bYCZyvSeYxCHKvzHG5eZjc+zyaS5BrBWya2+kQ==} + '@types/react-dom@19.2.4': + resolution: {integrity: sha512-Bsc+QHgp+P/F02XDzNCY9jnZNCUuLki36KT7VKrTXXLdHf+vHMNZnW1rVu5DNW/rCK+fya3DATySbLM4yhtKUw==} peerDependencies: '@types/react': ^19.2.0 @@ -1738,7 +1741,7 @@ snapshots: dependencies: undici-types: 6.21.0 - '@types/react-dom@19.2.3(@types/react@19.2.17)': + '@types/react-dom@19.2.4(@types/react@19.2.17)': dependencies: '@types/react': 19.2.17