-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
[v2] StaticQuery doesn't work with typescript #5626
Comments
I've narrowed this down to not being a typescript issue, but actually due to JSX being transpiled before it hits the file parser. Using static queries without JSX example does not work because the resulting AST is different than expected here: https://github.com/gatsbyjs/gatsby/blob/v2/packages/gatsby/src/internal-plugins/query-runner/file-parser.js#L119 For example this expression will reproduce the issue in a regular JS gatsby environment: React.createElement(StaticQuery, {
query: graphql`
query LayoutQuery {
site {
siteMetadata {
title
}
}
}
`,
render: data => data.site.siteMetadata.title
}); Should the file parser be modified to extract graphql queries from createElement calls? |
Yeah — that seems like a good solution. Would help with other compile-to-js languages as well. |
Want to do a PR? |
Wouldn't the switch from |
Yeah that should do it! For ts-loader setting JSX to "preserve" in compilerOptions fixes the issue as well because babel transpiles the JSX after the static queries are extracted. https://www.typescriptlang.org/docs/handbook/jsx.html If the short-term plan is to switch to babel's typescript preset then no further action should be required. |
I'm still getting this with beta.11. I get Loading (StaticQuery) in development, and in production I get
I've changed jsx to preserve, with no effect. Should I open a new issue? |
I just wanted to point out that this bug is still reproducible. StaticQuery in TS component works fine in dev mode, but produces I wish I'd find this issue earlier. Changing my component to plain JS fixed the problem. |
Hi, this issue is still happening on |
Description
StaticQuery's are forever stuck in the "Loading (StaticQuery)" state in both development and production build when using typescript.
Steps to reproduce
I've created a minimal example reproducing the issue.
https://github.com/dannywils/gatsby-typescript-staticquery
Expected result
The StaticQuery should be extracted, executed and the render function should be called with the query results.
Actual result
The static query is replaced with Loading (StaticQuery)
Environment
File contents (if changed)
gatsby-config.js
: https://github.com/dannywils/gatsby-typescript-staticquery/blob/master/gatsby-config.jspackage.json
: https://github.com/dannywils/gatsby-typescript-staticquery/blob/master/package.jsongatsby-node.js
: https://github.com/dannywils/gatsby-typescript-staticquery/blob/master/gatsby-node.jsgatsby-browser.js
: N/Agatsby-ssr.js
: N/AThe text was updated successfully, but these errors were encountered: