Comments (9)
I encountered the same problem recently. After dived into the source code of CodeMirror and fixed my issue I think it is better to share my experience here. In case someone else get stuck by this really weird, tricky issue.
TL;DR: Find a way to ensure graphiql.css
is loaded before <GraphiQL />
get rendered. Be very careful when playing with Webpack code-splitting and GraphiQL at the same time.
My problem is highly related with the differences of the style processing between dev and prod of a customized version of start-react-app. I also used "code splitting" technique to split the GraphiQL and CodeMirror from the main bundle.
In general, in dev mode all styles are loaded in inline <style>
block by style-loader
and there's no problem. However, in prod mode, instead of being added to main.css
, the graphiql.css
was added to the chunk file which contained CodeMirror and GraphiQL.
It took me a lot of hours trying to upgrade my old react-relay
to the newest version (since apparently the graphiql
package required graphql@^0.10.5
via codemirror-graphql
via graphql-language-service-interface
) therefore I can upgrade graphiql
to the newest one. However after the upgrading I found the problem existing with the newest version. Then I started to set breakpoints and debug CodeMirror
. Then I found without the proper style, .CodeMirror-gutter.CodeMirror-foldgutter
became "display: block
" instead of "display: inline-block
". The width of that element cascaded to all its parent elements and caused the disaster. Even graphiql.css
was loaded immediately after the initialization, the mess didn't go away.
Once found the problem, I changed my code to ensure that graphiql.css
must be loaded before <GraphiQL />
get rendered. The problem was gone.
from graphiql.
Whoa this is crazy, what browser/OS are you using? Can you also verify that you have the graphiql.css file loaded into the browser?
from graphiql.
nothing crazy. chrome on osx.
I guess I took the readme example a little to literally and used just
import React from 'react';
import GraphiQL from 'graphiql';
import fetch from 'isomorphic-fetch';
function graphQLFetcher(graphQLParams) {
return fetch(window.location.origin + '/graphql', {
method: 'post',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(graphQLParams),
}).then(response => response.json());
}
React.render(<GraphiQL fetcher={graphQLFetcher} />, document.body);
and an index.html of
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>GraphiQL on localhost</title>
</head>
<body>
<script src="/static/bundle.js"></script>
</body>
</html>
and served the above with webpack-dev-server
I now see you have examples using static asset css files. I'll introduce that to my index and I'm sure it'll fix things... I'll confirm in a bit
from graphiql.
I was assuming all inline styles in the <GraphiQL />
component :)
from graphiql.
Ok just needed to add css-loader to webpack.config and all is good again.
from graphiql.
@philiptzou do you have recommendations as to how you ensure the stylesheet is loaded first? Or could you share how you went about this?
from graphiql.
I used setTimeout()
to delay the rendering of <GraphiQL />
element. I know it's not 100% guaranteed but it is enough for my case. If you need to ensure the loading sequence, I think you can use setInterval()
to check if the codemirror.css
was loaded, then setState()
to render <GraphiQL />
element and clearInterval()
.
from graphiql.
@philiptzou any guidance on what value for setInterval()
worked for you?
from graphiql.
@hotgazpacho I think any value larger than 0 for setInterval()
is acceptable as long as the delay isn't perceptible to the user. How about 100?
from graphiql.
Related Issues (20)
- [lsp-server] 🐞 Pending response rejected since connection got disposed HOT 4
- [lsp-server] 🐞 Adding whitespaces\newlines causes autocompletion to move up a level HOT 5
- Don't export react with cdn bundle
- [graphiql] <title>MDUxRUVCM0Y3QjQwNzgwMDZDNjczQTMxMEIyRkZEMEIwMDI4MjhGMUQ0NkI4RjI5RTREMjE4QzhBM0FDNDdBOA==
- [lsp-server] Support go to definition for implementation first graphql setups HOT 1
- vscode-graphql-syntax javascript - line between graphql( and ` character breaks syntax highlighting HOT 2
- [graphiql] Grafana Embedded GraphiQL Editor CodeMirror info tooltips links navigate away from page HOT 4
- [graphiql] Fragment variables not supported HOT 4
- [graphiql] Default Value not accepted in Variable
- [graphiql] bump markdown-it for SNYK-JS-MARKDOWNIT-6483324 HOT 1
- [graphiql] cm6-graphql | Cannot use import statement outside a module | import { getTokenAtPosition, getTypeInfo, getAutocompleteSuggestions, getDiagnostics } from 'graphql-language-service';
- [graphiql] Upgrade to @graphiql/react breaks unit tests
- [graphiql] Cannot edit query name from explorer plugin
- [lsp-server] <title> Sending request for data to server
- [graphiql] <title>pluginapi
- [lsp-server] 🐞 Constant syntax errors if a file is named `exports.graphqls` HOT 1
- [lsp-server] Support JS/TS files as schema files HOT 4
- [lsp-server] 🐞 JS/TS files should only be checked when included in `documents` config glob HOT 2
- [graphiql] Graphiql editor information is scoped to the origin
- [lsp-server] Add configuration to disable/enable for certain files. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphiql.