restore GraphQL syntax highlighting across Monaco editors (#7981)

This commit is contained in:
Jonathan Brennan 2026-04-15 12:01:08 -05:00 committed by GitHub
parent 9c6989cd92
commit 5706e2de0e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 1 deletions

View file

@ -1,6 +1,18 @@
import { lazy } from 'react';
// Import from `editor.api` rather than the `monaco-editor` main entry to keep
// the bundle lean — the main entry auto-registers every basic language, which
// bloats our client sourcemaps. We opt in to the contributions we actually use
// via the side-effect imports below.
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
// Enables the read-only tooltip shown when users type into a read-only model.
import 'monaco-editor/esm/vs/editor/contrib/readOnlyMessage/browser/contribution.js';
// Registers the basic GraphQL Monarch tokenizer so `language="graphql"` models
// get syntax highlighting. Without this, `editor.api` ships no languages.
import 'monaco-editor/esm/vs/basic-languages/graphql/graphql.contribution.js';
// Registers the JSON language service (`monaco.languages.json`) — required by
// the policy naming-convention rule editor, which configures JSON schema
// diagnostics in `beforeMount`.
import 'monaco-editor/esm/vs/language/json/monaco.contribution.js';
import {
loader,
DiffEditor as MonacoDiffEditor,

View file

@ -660,7 +660,11 @@ function PreflightModal({
}, []);
const handleMonacoEditorBeforeMount = useCallback(async (monaco: Monaco) => {
if (monaco.languages.typescript) {
// Lazy-load the TS language service on first preflight mount if it hasn't
// already been registered. `schema-editor.ts` configures Monaco with the
// lean `editor.api` entry (no languages bundled), so `monaco.languages
// .typescript` is only defined after this side-effect import has run.
if (!monaco.languages.typescript) {
await import('monaco-editor/esm/vs/language/typescript/monaco.contribution');
}