-
Notifications
You must be signed in to change notification settings - Fork 123
Local bundling of the Monaco editor for predictable code editor loading behaviour on Shesha #4438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ng behaviour on shesha.
WalkthroughReplaces CDN-based Monaco initialization with a local bundled setup. Adds Changes
Sequence Diagram(s)sequenceDiagram
participant App as Client Component
participant Loader as Monaco Loader (requirejs)
participant Monaco as monacoSetup (monaco instance)
participant Worker as Local Worker Script
App->>Loader: import / initialize loader
App->>Monaco: import monacoSetup
Loader->>Monaco: loader.config({ monaco })
App->>Monaco: create Editor instance
Monaco->>Monaco: MonacoEnvironment.getWorker(kind, label)
Monaco->>Worker: instantiate worker via import.meta.url -> local ESM worker
Worker-->>Monaco: worker ready
Monaco-->>App: editor ready
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@shesha-reactjs/src/components/codeEditor/client-side/monacoSetup.ts`:
- Around line 11-53: Define a proper global type for MonacoEnvironment and
assign it to globalThis without using an any cast: add a TypeScript global
declaration that declares MonacoEnvironment with the correct getWorker signature
(e.g., getWorker(moduleId: string, label: string): Worker) so the file can set
globalThis.MonacoEnvironment = { getWorker(...) { ... } } directly; update
monacoSetup.ts to reference globalThis.MonacoEnvironment and remove the (self as
any) cast while keeping the existing worker-return logic in the getWorker
implementation.
…up.ts Strict typing as suggested by code rabbit Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
…onacoSetup.ts " This reverts commit 6f4d260.
IvanIlyichev
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @teboho. Local bundling requires reconfiguration of rollupjs build. Proposed changes can't be used as is because build of applicaitons that uses @shesha-io/reactjs fails with error ReferenceError: window is not defined. You can test it using shesha-functional-tests\adminportal
Hi @IvanIlyichev I will make changes. |
#4439
Monaco Editor Local Bundling
Overview
This document describes the configuration changes made to bundle Monaco Editor locally instead of loading it from a CDN. This significantly improves load times for the code editor component.
Changes Made
1. Monaco Setup File (
src/components/codeEditor/client-side/monacoSetup.ts)Created a new setup file that:
new URL()andimport.meta.url2. Code Editor Client Side (
src/components/codeEditor/client-side/codeEditorClientSide.tsx)Updated the file to:
@monaco-editor/reactloader to use the local Monaco instanceBefore:
After:
3. Next.js Configuration (
next.config.js)Added webpack configuration to:
Benefits
Technical Details
Worker Configuration
Monaco Editor uses Web Workers for language services (TypeScript IntelliSense, syntax checking, etc.). The setup file configures these workers to be bundled using Next.js's built-in worker support:
Next.js automatically:
Bundle Impact
Monaco Editor adds approximately 3-4MB to the bundle size when minified. However:
Performance Comparison
Before (CDN)
cdn.jsdelivr.netAfter (Local Bundle)
Maintenance
Updating Monaco Editor
To update Monaco Editor version:
Update the package version in
package.json:No code changes required - the local bundling configuration will automatically use the new version
Troubleshooting
If the editor fails to load:
npm list monaco-editorrm -rf .nextnpm run build-nextDevelopment vs Production
The configuration works identically in both development and production modes. Next.js handles the worker bundling appropriately for each environment.
Rollback
To revert to CDN loading, change
codeEditorClientSide.tsx:Related Files
/src/components/codeEditor/client-side/monacoSetup.ts- Monaco worker configuration/src/components/codeEditor/client-side/codeEditorClientSide.tsx- Main editor component/next.config.js- Webpack configuration for Monaco assets/package.json- Monaco editor dependenciesReferences
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.