useStaticQuery fails to fetch when used inside a lazy loaded component #37696
Labels
status: triage needed
Issue or pull request that need to be triaged and assigned to a reviewer
type: bug
An issue or pull request relating to a bug in Gatsby
Preliminary Checks
Description
I'm pursuing an upgrade path from using
gatsby-plugin-loadable-components-ssr
with Gatsby 4 toReact.lazy
with Gatsby 5. However, when I try to use a static query inside a dynamically loaded component, I get:Error in function useStaticQuery in ./.cache/static-query.js:83 The result of this StaticQuery could not be fetched. This is likely a bug in Gatsby and if refreshing the page does not fix it, please open an issue in https://github.com/gatsbyjs/gatsby/issues
A bare minimum component for this use case looks like this:
I've also tried putting the static query in a separate file as its own hook and get the same error. I'm gathering the components for a given page like this:
I'm getting this error in both
develop
andbuild
.Reproduction Link
https://github.com/pseelinger/gatsby-usestaticquery-bug
Steps to Reproduce
React.lazy
Expected Result
The page should render with the value of the result of the static query displayed in the component. Build should complete without errors.
Actual Result
The page does not render and the static query fails to run with the above error. Build fails with the error
WebpackError: The result of this StaticQuery could not be fetched.
Environment
Config Flags
No response
The text was updated successfully, but these errors were encountered: