Skip to content

Commit

Permalink
avoid top-level dynamic codemirror imports (#2545)
Browse files Browse the repository at this point in the history
* avoid top-level codemirror imports

* adjust changeset message
  • Loading branch information
thomasheyenbrock authored Jul 6, 2022
1 parent 4ad0793 commit 8ce5b48
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/tame-owls-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphiql/react': patch
---

Avoid top-level dynamic imports from `codemirror` that break importing the package in non-browser environments
29 changes: 14 additions & 15 deletions packages/graphiql-react/src/editor/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,6 @@ export const commonKeys = {
'Alt-Right': 'goGroupRight',
};

export const commonCodeMirrorAddons = [
import('codemirror/addon/hint/show-hint'),
import('codemirror/addon/edit/matchbrackets'),
import('codemirror/addon/edit/closebrackets'),
import('codemirror/addon/fold/brace-fold'),
import('codemirror/addon/fold/foldgutter'),
import('codemirror/addon/lint/lint'),
import('codemirror/addon/search/searchcursor'),
import('codemirror/addon/search/jump-to-line'),
import('codemirror/addon/dialog/dialog'),
// @ts-expect-error
import('codemirror/keymap/sublime'),
];

/**
* Dynamically import codemirror and dependencies
* This works for codemirror 5, not sure if the same imports work for 6
Expand All @@ -47,7 +33,20 @@ export async function importCodeMirror(
const allAddons =
options?.useCommonAddons === false
? addons
: commonCodeMirrorAddons.concat(addons);
: [
import('codemirror/addon/hint/show-hint'),
import('codemirror/addon/edit/matchbrackets'),
import('codemirror/addon/edit/closebrackets'),
import('codemirror/addon/fold/brace-fold'),
import('codemirror/addon/fold/foldgutter'),
import('codemirror/addon/lint/lint'),
import('codemirror/addon/search/searchcursor'),
import('codemirror/addon/search/jump-to-line'),
import('codemirror/addon/dialog/dialog'),
// @ts-expect-error
import('codemirror/keymap/sublime'),
...addons,
];
await Promise.all(allAddons.map(addon => addon));
return CodeMirror;
}

0 comments on commit 8ce5b48

Please sign in to comment.