Skip to content

Conversation

@ikhoon
Copy link
Contributor

@ikhoon ikhoon commented Dec 31, 2025

Motivation:

Central Dogma should be used in an isolated network environment without accessing the internet. However, Monaco Editor dynamically loads workers from internet. See #1236 for details.

Modifications:

  • Use monaco-editor-webpack-plugin to load Monaco Editor resources with WebPack.
  • Use loader from '@monaco-editor/react' to load resources locally instead of CDN
  • Lazily loading monaco-editor in the client side only to avoid accessing the window object on the server.

Result:

Motivation:

Central Dogma should be used in an isolated network environment without
accessing the internet. However, Monaco Editor dynamically loads workers
from internet. See line#1236 for details.

Modifications:

- Use `monaco-editor-webpack-plugin` to load Monaco Editor resources
  with WebPack.
- Use `loader` from '@monaco-editor/react' to load resources locally
  instead of CDN
- Lazily loading `monaco-editor` in the client side only to avoid
  accessing the `window` object on the server.

Result:

- You can now use Central Dogma UI without internet access.
- Closes line#1236
@ikhoon ikhoon added the defect label Dec 31, 2025
@ikhoon ikhoon added this to the 0.79.0 milestone Dec 31, 2025
@coderabbitai
Copy link

coderabbitai bot commented Dec 31, 2025

📝 Walkthrough

Walkthrough

This PR bundles the Monaco Editor locally by extending Next.js webpack configuration with MonacoWebpackPlugin and updating dependencies, then adds loading guards in FileEditor and NewFile components to handle Monaco initialization before rendering.

Changes

Cohort / File(s) Summary
Configuration & Dependencies
webapp/next.config.js, webapp/package.json
Extends Next.js webpack config with MonacoWebpackPlugin to transpile and bundle Monaco packages locally; adds monaco-editor-webpack-plugin to both dependencies and devDependencies; configures worker file output under static/[name].worker.js on client builds.
Monaco Initialization Infrastructure
webapp/src/dogma/features/file/MonacoLoader.ts
New React hook module providing useLocalMonaco that dynamically imports monaco-editor at runtime and configures worker URLs for JSON, JavaScript/TypeScript, and default editor workers; returns monaco instance or null before load completion.
Component Loading Guards
webapp/src/dogma/common/components/editor/FileEditor.tsx, webapp/src/dogma/features/file/NewFile.tsx
Both components now check Monaco readiness via useLocalMonaco hook; renders Loading component until Monaco is available before proceeding with form or editor render.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A bundled editor, no CDN in sight!
Monaco travels locally, working day and night.
Loading guards stand ready, with patient care,
Now air-gapped desktops needn't despair! 📦✨

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Bundle Monaco Editor workers' directly and clearly summarizes the main change—bundling Monaco Editor workers locally instead of loading from CDN.
Description check ✅ Passed The description is well-related to the changeset, explaining motivation, modifications, and results that align with the code changes for bundling Monaco Editor resources.
Linked Issues check ✅ Passed The PR successfully addresses issue #1236 by bundling Monaco Editor resources locally via webpack plugin and loader configuration, enabling offline functionality without CDN access.
Out of Scope Changes check ✅ Passed All changes are directly scoped to bundling Monaco Editor workers and configuring local loading, with no unrelated modifications detected in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ikhoon
Copy link
Contributor Author

ikhoon commented Dec 31, 2025

image

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
webapp/src/dogma/features/file/MonacoLoader.ts (1)

24-46: Prefer explicit typing over any for better type safety.

Line 26 uses any for the monaco instance, which bypasses TypeScript's type checking and could lead to runtime errors.

🔎 Recommended fix to use proper Monaco types
+import type * as monacoType from 'monaco-editor';
+
 export const useLocalMonaco = () => {
-  //eslint-disable-next-line @typescript-eslint/no-explicit-any
-  const [monaco, setMonaco] = useState<any>(null);
+  const [monaco, setMonaco] = useState<typeof monacoType | null>(null);

This provides better IntelliSense and catches type errors at compile time.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d3bf2b0 and 4c9c1cc.

⛔ Files ignored due to path filters (1)
  • webapp/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (5)
  • webapp/next.config.js
  • webapp/package.json
  • webapp/src/dogma/common/components/editor/FileEditor.tsx
  • webapp/src/dogma/features/file/MonacoLoader.ts
  • webapp/src/dogma/features/file/NewFile.tsx
🧰 Additional context used
🧬 Code graph analysis (2)
webapp/src/dogma/features/file/NewFile.tsx (2)
webapp/src/dogma/features/file/MonacoLoader.ts (1)
  • useLocalMonaco (24-46)
webapp/src/dogma/common/components/Loading.tsx (1)
  • Loading (3-8)
webapp/src/dogma/common/components/editor/FileEditor.tsx (2)
webapp/src/dogma/features/file/MonacoLoader.ts (1)
  • useLocalMonaco (24-46)
webapp/src/dogma/common/components/Loading.tsx (1)
  • Loading (3-8)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: build-ubuntu-latest-jdk-17-min-java-11
  • GitHub Check: build-macos-latest-jdk-25
  • GitHub Check: build-ubuntu-latest-jdk-25-snapshot
  • GitHub Check: build-ubuntu-latest-jdk-21
  • GitHub Check: build-windows-latest-jdk-25
  • GitHub Check: build-ubuntu-latest-jdk-11
  • GitHub Check: lint
  • GitHub Check: build-ubuntu-latest-jdk-17-coverage
  • GitHub Check: flaky-tests
  • GitHub Check: docker-build
🔇 Additional comments (3)
webapp/src/dogma/features/file/MonacoLoader.ts (1)

5-22: LGTM: Worker paths align with webpack configuration.

The worker URLs correctly match the filename pattern configured in next.config.js line 24 (static/[name].worker.js). The check for existing window.MonacoEnvironment prevents overwriting if already set.

webapp/src/dogma/features/file/NewFile.tsx (1)

36-37: LGTM: Loading guard correctly prevents premature rendering.

The implementation correctly waits for Monaco to load before rendering the editor form. This pattern is consistent with FileEditor.tsx and prevents errors from accessing Monaco before it's initialized.

Also applies to: 143-146

webapp/src/dogma/common/components/editor/FileEditor.tsx (1)

30-31: LGTM: Loading guard ensures Monaco is available before rendering.

The loading guard correctly prevents the component from rendering until Monaco is initialized. This pattern is consistent with the implementation in NewFile.tsx and prevents runtime errors from premature Monaco API access.

Also applies to: 111-114

setMonaco(monacoInstance);
})
.catch((err) => {
console.error('Failed to load local monaco-editor:', err);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted that if the editor is stuck at <Loading />, checking the console might help debug issues

Copy link
Contributor

@minwoox minwoox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@ikhoon ikhoon merged commit 2da2667 into line:main Jan 6, 2026
11 of 12 checks passed
@ikhoon ikhoon deleted the bundle-monaco branch January 6, 2026 02:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Monaco Editor seems to require internet connection to jsdelivr CDN

3 participants