-
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
fix(gatsby): correctly replace exported queries for StaticQuery #11545
fix(gatsby): correctly replace exported queries for StaticQuery #11545
Conversation
This PR fixes the static query extraction (rather the import statement) failing when the query is `export`ed. The issue was that the AST was expected to be at a certain depth (e.g. the .parentPath stuff), and we need to go up _one_ more level to get the correct element we expected, i.e. the component. Fixes gatsbyjs#11477
@@ -76,12 +83,12 @@ function removeImport(tag) { | |||
else importPath.remove() | |||
} | |||
if (importPath.isObjectProperty()) { | |||
if (parent.node.properties.length === 1) | |||
importPath.findParent(p => p.isVariableDeclaration())?.remove() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These were causing eslint to go wild. I lightly refactored this and used a helper.
I used this example to validate this PR. Doesn't seem to cause any regressions as best as I can tell, just fixes the bug. |
Nice! Hopefully this is the main bug that people keep hitting with static queries. |
@KyleAMathews I think this is one of them. The other is the one that @tkh44 @jlengstorf seem to be intermittently hitting, i.e. something like I think that's a monorepo/workspaces bug though, not necessarily something with StaticQuery. Still need to research it more though. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one @DSchau!
|
Description
This PR fixes the static query extraction (rather the import statement)
failing when the query is
export
ed. The issue was that the AST wasexpected to be at a certain depth (e.g. the .parentPath stuff), and we
need to go up one more level to get the correct element we expected,
i.e. the component.
I also added an e2e test to guard against this behavior in the future.
Related Issues
Fixes #11477