fix: pin Monaco to 0.52.2 to stop intermittent editor load failures - #997
Merged
Conversation
Monaco 0.53.0 declares its minified helper variables with `var` at the top level of every chunk file. AMD chunks are plain scripts rather than modules, so those helpers land on `window`: a live load leaks h, m, r, o, p, s, i, f, u, w, M, y and C. Different chunks give the same name different meanings -- `m` is the field-setter helper in language/css/monaco.contribution.js but is Object.defineProperty in yaml.contribution.6f43d486.js -- so whichever chunk script evaluates last wins. When yaml wins, the css chunk's `r(this, "_options")` call resolves to Object.defineProperty(this, "_options", undefined) and throws "Property description must be an object: undefined". The editor.main callback then never fires, ensureMonaco() times out after 30s, and submitpage.php falls back to the bare textarea. Evaluation order depends on network timing, which is why it only reproduces on some page loads. This is upstream microsoft/monaco-editor#5015, fixed in 0.54.0. cdnjs has no stable release newer than 0.53.0, and the rest of the script sources from cdnjs, so pin back to 0.52.2 -- it ships as a single bundle and leaks no globals at all. Also make ensureMonaco() single-flight. Overlapping callers (submit editor, merge view, freopen snippets) each appended their own loader.js, and the second loader resets the AMD registry while the first is still resolving modules. A failed load clears the cached promise so later calls can retry. Closes #991 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Contributor
|
🧙 Sourcery has finished reviewing your pull request! Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Deploying xmoj-script-dev-channel with
|
| Latest commit: |
f0a8826
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://0d8671fd.xmoj-script-dev-channel.pages.dev |
| Branch Preview URL: | https://fix-monaco-load-failure-991.xmoj-script-dev-channel.pages.dev |
Member
Author
|
Can confirm works |
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.
What does this PR aim to accomplish?:
Closes #991 — Monaco Editor intermittently fails to load on
submitpage.php, leaving the plain<textarea>fallback. The console shows:This is upstream microsoft/monaco-editor#5015, a regression in 0.53.0 — the exact version
MonacoCDNwas pinned to (added in #989).0.53.0 switched to a chunked build whose minified helper variables are declared with
varat file top level. AMD chunks are plain scripts, not ES modules, so those helpers land onwindow. Probing a live 0.53.0 load confirms 13 leaked single-letter globals:mis the collision. Inlanguage/css/monaco.contribution.jsit is the field-setter helper; inyaml.contribution.6f43d486.jsit isObject.defineProperty. Whichever chunk script evaluates last wins, and that depends on network timing — hence the "only sometimes, reproduce by refreshing" behaviour.When
yamlwins, the css chunk'sr(this, "_options")(two args, so the value isundefined) becomesObject.defineProperty(this, "_options", undefined). Replaying that in isolation reproduces the reported message verbatim:Monaco then never finishes loading, the
require(['vs/editor/editor.main'])callback never fires,ensureMonaco()rejects on its 30s timeout, and the fallback textarea from the issue's screenshot is shown.How does this PR accomplish the above?:
Pin
MonacoCDNto 0.52.2 (XMOJ.user.js:554). 0.52.2 ships as a singleeditor.main.jsbundle, so there are no cross-chunk globals to collide — the same probe against 0.52.2 comes back completely empty. Upstream fixed the leak in 0.54.0, but cdnjs has no stable release newer than 0.53.0 (0.54.0+ exist only on npm/jsDelivr). Since every other dependency in this script is served from cdnjs, and jsDelivr has a poor reliability record in mainland China, downgrading was preferred over switching CDN hosts. A comment in the code records why.Make
ensureMonaco()single-flight (XMOJ.user.js:758). This was a second, independent way for loading to fail: overlapping callers (submit page editor, merge view, freopen snippets) each appended their ownloader.js, and the second loader resets the AMD registry while the first is still resolving modules. The load promise is now cached, and cleared on failure so later calls can still retry.No API surface changes — the script only uses
monaco.editor.create,monaco.editor.createDiffEditor,monaco.editor.createModel,monaco.KeyModandmonaco.KeyCode, all long-stable and present in 0.52.2.Testing performed: loaded cdnjs 0.52.2 in headless Chrome via CDP and confirmed the editor renders (
.view-lineelements present), that every Monaco API this script uses works, and that no globals leak.node --check XMOJ.user.jspasses.By submitting this pull request, I confirm the following:
Summary by Sourcery
Pin the Monaco editor CDN version and make Monaco loading single-flight to prevent intermittent failures of the code editor on the submit page.
Bug Fixes:
Enhancements:
Summary by cubic
Pins
monaco-editoroncdnjsto 0.52.2 to stop intermittent editor load failures on the submit page and makesensureMonaco()single-flight. Bumps script version to 3.5.4. Closes #991.monaco-editorto 0.52.2 to avoid the 0.53.0 global-leak regression that breaks AMD chunk loads.ensureMonaco()(cleared on failure) to prevent duplicateloader.jsinserts that reset the AMD registry.Written for commit f0a8826. Summary will update on new commits.