Skip to content

fix: learn pages crashing due to codemirror #1402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"@weknow/gatsby-remark-twitter": "0.2.3",
"assert": "2.0.0",
"clsx": "1.2.1",
"codemirror": "6.0.1",
"codemirror-graphql": "2.0.5",
"codemirror": "5.65.1",
"codemirror-graphql": "1.2.11",
"gatsby": "5.8.1",
"gatsby-plugin-anchor-links": "1.2.1",
"gatsby-plugin-feed": "5.8.0",
Expand Down
21 changes: 20 additions & 1 deletion src/components/Marked/MiniGraphiQL.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import React from "react"
import { marked } from "marked"
import * as CodeMirror from "codemirror"

import { graphql, formatError, parse, typeFromAST } from "graphql"

Expand Down Expand Up @@ -140,6 +139,17 @@ class QueryEditor extends React.Component {
}

componentDidMount() {
var CodeMirror = require("codemirror")
require("codemirror/addon/hint/show-hint")
require("codemirror/addon/comment/comment")
require("codemirror/addon/edit/matchbrackets")
require("codemirror/addon/edit/closebrackets")
require("codemirror/addon/lint/lint")
require("codemirror/keymap/sublime")
require("codemirror-graphql/hint")
require("codemirror-graphql/lint")
require("codemirror-graphql/mode")

this.editor = CodeMirror(this.domNode, {
value: this.props.value || "",
viewportMargin: Infinity,
Expand Down Expand Up @@ -327,6 +337,15 @@ class VariableEditor extends React.Component {
componentDidMount() {
// Lazily require to ensure requiring GraphiQL outside of a Browser context
// does not produce an error.
const CodeMirror = require("codemirror")
require("codemirror/addon/hint/show-hint")
require("codemirror/addon/edit/matchbrackets")
require("codemirror/addon/edit/closebrackets")
require("codemirror/addon/lint/lint")
require("codemirror/keymap/sublime")
require("codemirror-graphql/variables/hint")
require("codemirror-graphql/variables/lint")
require("codemirror-graphql/variables/mode")

this.editor = CodeMirror(this.domNode, {
value: this.props.value || "",
Expand Down
Loading