Skip to content

Commit

Permalink
only initialize the mode once (#2834)
Browse files Browse the repository at this point in the history
* only initialize the mode once

* add the global api
  • Loading branch information
acao authored Oct 27, 2022
1 parent aaa43e4 commit 0a950ea
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
7 changes: 7 additions & 0 deletions .changeset/wet-planets-boil.md
Original file line number Diff line number Diff line change
@@ -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!
14 changes: 8 additions & 6 deletions packages/monaco-graphql/src/initializeMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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
(<any>languages).graphql = { api };

getMode().then(mode => mode.setupMode(api));
if (!api) {
api = createMonacoGraphQLAPI(LANGUAGE_ID, config);
(<any>languages).graphql = { api };
// export to the global monaco API
getMode().then(mode => mode.setupMode(api));
}

return api;
}
Expand Down

0 comments on commit 0a950ea

Please sign in to comment.