diff --git a/.changeset/wet-planets-boil.md b/.changeset/wet-planets-boil.md new file mode 100644 index 00000000000..6321ac4c106 --- /dev/null +++ b/.changeset/wet-planets-boil.md @@ -0,0 +1,7 @@ +--- +'monaco-graphql': patch +--- + +prevent the mode from instantiating more than once in the main process. it should never need to! + +you can supply multiple `schemas` with uri path resolution rules that resolve globs in the browser even! diff --git a/packages/monaco-graphql/src/initializeMode.ts b/packages/monaco-graphql/src/initializeMode.ts index 4436384be06..47335e75655 100644 --- a/packages/monaco-graphql/src/initializeMode.ts +++ b/packages/monaco-graphql/src/initializeMode.ts @@ -13,6 +13,8 @@ import { languages } from 'monaco-editor'; export const LANGUAGE_ID = 'graphql'; +let api: MonacoGraphQLAPI; + /** * Initialize the mode & worker synchronously with provided configuration * @@ -22,12 +24,12 @@ export const LANGUAGE_ID = 'graphql'; export function initializeMode( config?: MonacoGraphQLInitializeConfig, ): MonacoGraphQLAPI { - const api = createMonacoGraphQLAPI(LANGUAGE_ID, config); - - // export to the global monaco API - (languages).graphql = { api }; - - getMode().then(mode => mode.setupMode(api)); + if (!api) { + api = createMonacoGraphQLAPI(LANGUAGE_ID, config); + (languages).graphql = { api }; + // export to the global monaco API + getMode().then(mode => mode.setupMode(api)); + } return api; }