Repository navigation
fix(plugin-editor): serve Monaco from the Console's own build instead of cdn.jsdelivr.net - #25993
Merged
Merged
Conversation
…elivr WIP: shared bundledMonaco loader (ESM core + ?worker language workers), MonacoImpl textarea fallback, app-shell probe configures before init. Claude-Session: https://claude.ai/code/session_0144tqLAVSHy6hGKUSH4LhVL Co-authored-by: Claude <noreply@anthropic.com>
The bundled Monaco loader imports only the core up front; each language worker is imported when Monaco first asks for it. MonacoImpl gets its chunk-failure and no-CDN tests; the app-shell Monaco tests stub configureBundledMonaco, and the two real-loader tests now model a chunk that cannot be fetched instead of a CDN script. Claude-Session: https://claude.ai/code/session_0144tqLAVSHy6hGKUSH4LhVL Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0144tqLAVSHy6hGKUSH4LhVL Co-authored-by: Claude <noreply@anthropic.com>
Contributor
Author
席位核对 · ACCEPT · seat
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Steve · project thread
Fixes #25899
Clause-②: no
Metadata-protocol: none
What changed
The Console's code editors loaded Monaco's core from
cdn.jsdelivr.netat run time, because nothing inui/ever calledloader.configand@monaco-editor/loader1.7.0 defaultspaths.vsto the jsdelivrmonaco-editor@0.55.1AMD build. Under the Console's CSP (script-src 'self' 'nonce-…', no CDN, noworker-src) that script is refused, so every surface fell back to a textarea and thecode-editorpage component stayed on "Loading..." for good.@object-ui/plugin-editormonaco-editor@^0.55.1is now a runtime dependency (the maintainer approved it on 2026-10-25, option A, self-host).bundledMonaco.tswithconfigureBundledMonaco(loader). It importsmonaco-editoras a lazy ESM chunk and callsloader.config({ monaco })before the firstloader.init(). A loader that already holds an instance resolvesinit()with it and injects no script.self.MonacoEnvironment.getWorkerimports each language worker through Vite's?workerthe first time Monaco asks for that label (json, css/scss/less, html/handlebars/razor, typescript/javascript, and the editor worker for the rest). Each worker starts from a same-origin file underassets/.MonacoImplmounts<Editor>only once that config has landed. When the editor chunk cannot be fetched, it edits the same text in a plain textarea (read-only kept) and warns once, instead of loading forever.@object-ui/app-shelluseMonacoFallback's one loader probe per page now awaitsconfigureBundledMonaco(through a dynamicimport('@object-ui/plugin-editor'), because the probe sits in the eager closure) beforeloader.init().CodeWidgetall mount through that probe, so all of them get the bundled Monaco. The plain-textarea fallback stays for a chunk that cannot be fetched, and the report now names the chunk URL the browser could not fetch.ui/apps/console/vite.config.ts: Vite's default?workeroutput already emits same-origin worker files, so no worker output config was needed.Bundle size (console
vite build, before =d5f4c2a2, after = this branch)du -sh dist/assetseager-closure.json)No Monaco, editor or worker chunk is in the first-paint closure. The added bytes are lazy files loaded only on a screen that opens an editor:
codicon.ttfis also added.Browser smoke under the Console CSP
Setup:
osshowcase backend serving this branch's console build, withOS_PAGE_REACT_ENABLED=false.unsafe-eval, no CDN inscript-src, noworker-src.CodeWidget(metadata form code field)showcase_normalize_task_titleJsonSourceEditor(Source tab)showcase_taskSourcePageEditorshowcase_start_heresecuritypolicyviolationevents (script-src or worker-src).cdn.jsdelivr.net.ts.worker-*.jsandeditor.worker-*.jsloaded from/_console/assets/(same origin).code-editorpage component. It renders the sameMonacoImplthat the tests below cover.Tests
New tests in
ui/packages/plugin-editor:bundledMonaco.noCdn.test.tsx. Uses the real@monaco-editor/loaderand the realMonacoImpl.<Editor>mounts only after the loader holds the bundled Monaco.loader.init()answers with it, and no jsdelivr orvs/loader.jsscript is appended.getWorkermaps each label to its worker module.MonacoImpl.chunkFailure.test.tsx. Importingmonaco-editorrejects, which covers card bullet 3.onChangefires.Reverse verification, run with
scripts/ablation-replace.mjs. Each mutation landed as an on-disk blob change and was restored to an emptygit diff HEAD:loader.config(...)fromconfigureBundledMonacoturns noCdn red: "the loader held the bundled Monaco when Editor mounted: expected false to be true".unavailablebranch inMonacoImplturns both chunkFailure tests red: "Unable to find a label with the text of: javascript source".app-shell suites:
@monaco-editor/reactnow also stubconfigureBundledMonaco.useMonacoFallback.loaderRejection-11800andCodeWidget.loaderFallback-11858now fail the chunk import itself. They assert that the report names the chunk URL and that no loader script is ever appended.Results at
32c20ded:packages/app-shell/+packages/plugin-editor/run from the ui root: 1724 test files passed, 1 skipped (1725); 15880 tests passed, 9 skipped.Gates:
node scripts/pm/dispatch-gates.mjs --ranreports 53 derived, 53 run, 0 NOT-MEASURED, 0 UNRUN.check:dts-closureandcheck:dual-build-cjs-loadsfirst stopped on missing build output: the consoleplugin.d.ts, and seven backend packages with nodist/. Both passed after building those outputs.Acceptance notes
ui/packages/app-shell/src/views/studio-design/got the same one-lineconfigureBundledMonacostub:InterfacesPillar.sourcePage-12522,StudioDesignSurface.interfacesCreatePage-11823andStudioDesignSurface.interfacesReadOnly-11136.ui/apps/siteplayground (apps/site/app/playground/page.tsx) still loads Monaco from the CDN.packages/cli/src/utils/console.ts, nearconsoleContentSecurityPolicy. It still says Monaco loads its core from jsdelivr and shows its plain-text fallback. That file is outside this card's surface.@monaco-editor/loader's default config inside an eager chunk. It is never requested onceloader.config({ monaco })has run, and the smoke above shows zero requests to it.'unsafe-eval', which does not affect where scripts or workers may load from.@object-ui/plugin-editorwith something other than Vite must resolve the?workerimports itself (noted in the changeset).🤖 Generated with Claude Code
https://claude.ai/code/session_0144tqLAVSHy6hGKUSH4LhVL