Skip to content
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 graphql fails with whitespace #7752

Closed
audiolion opened this issue Aug 30, 2018 · 6 comments · Fixed by #7846
Closed

[v2] StaticQuery graphql fails with whitespace #7752

audiolion opened this issue Aug 30, 2018 · 6 comments · Fixed by #7846
Assignees
Labels
status: confirmed Issue with steps to reproduce the bug that’s been verified by at least one reviewer. type: bug An issue or pull request relating to a bug in Gatsby

Comments

@audiolion
Copy link

audiolion commented Aug 30, 2018

Description

[v2] In the new StaticQuery component the graphql gatsby export fails if there is whitespace in the graphql document.

Steps to reproduce

This is a component defined in the components directory that never loads:

import React from 'react';
import { StaticQuery, graphql } from 'gatsby';

const Layout = ({ children, location }) => (
  <StaticQuery
    query={graphql`
      query SiteData {
        site {
          siteMetadata {
            title
            description
            keywords
          }
        }
        allContentfulProject {
          edges {
            node {
              id
              name
              slug
            }
          }
        }
      }
    `}
    render={data => (
      {children}
    )}
  />
);

export default Layout;

Browser:
image

React tree:
image

When I remove the extra whitespace and format the code like this it works:

import React from 'react';
import { StaticQuery, graphql } from 'gatsby';

const Layout = ({ children, location }) => (
  <StaticQuery
    query={graphql`
  query SiteData {
    site {
      siteMetadata {
        title
        description
        keywords
      }
    }
    allContentfulProject {
      edges {
        node {
          id
          name
          slug
        }
      }
    }
  }
`}
    render={data => (
      {children}
    )}
  />
);

export default Layout;

Expected result

graphql document should be parsed, page should load

Actual result

Sits on Loading and never updates with data

Environment

System:
OS: macOS High Sierra 10.13.6
CPU: x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
Shell: 4.4.19 - /usr/local/bin/bash
Binaries:
Node: 10.8.0 - ~/.nodenv/shims/node
Yarn: 1.9.4 - /usr/local/bin/yarn
npm: 6.2.0 - ~/.nodenv/shims/npm
Browsers:
Chrome: 68.0.3440.106
Firefox: 59.0.1
Safari: 11.1.2
npmPackages:
gatsby: next => 2.0.0-rc.4
gatsby-image: next => 2.0.0-rc.1
gatsby-plugin-emotion: next => 2.0.0-rc.1
gatsby-plugin-google-fonts: next => 0.0.4
gatsby-plugin-react-helmet: next => 3.0.0-rc.1
gatsby-plugin-sharp: next => 2.0.0-rc.2
gatsby-remark-images: next => 2.0.1-rc.1
gatsby-source-contentful: next => 2.0.1-rc.2
gatsby-source-filesystem: next => 2.0.1-rc.1
gatsby-transformer-remark: next => 2.1.1-rc.1
gatsby-transformer-sharp: next => 2.1.1-rc.2
npmGlobalPackages:
gatsby-cli: 2.0.0-rc.1

File contents (if changed)

gatsby-config.js: N/A
package.json: N/A
gatsby-node.js: N/A
gatsby-browser.js: N/A
gatsby-ssr.js: N/A

@audiolion
Copy link
Author

To just add a bit more here, sometimes this doesn't reproduce and sometimes it does, it is like it gets caught in some caching issue and by moving the whitespace around it invalidates the cache and fixes it.

@cwgw
Copy link
Contributor

cwgw commented Aug 30, 2018

I am experiencing this as well, and I'm pretty sure a cache invalidation problem.

rm -rf .cache and rerunning gatsby develop fixes the problem until you make further changes to your StaticQuery query (including addition/deletion of whitespace). Doing so repeatedly results in a bunch of new json files in public/static/d/ with different file names but identical content.

It seems that any change to the query—even whitespace changes—produces a different hashed id (by babel-plugin-remove-graphql-queries?) and causes the check in gatsby-browser-entry to fail.

Steps to reproduce

Create a new site with the v2 default starter.

gatsby new gatsby-site https://github.com/gatsbyjs/gatsby-starter-default#v2

Run gatsby develop.

Open up src/components/layout.js and stick a few extra spaces into the StaticQuery's query prop

  <StaticQuery
    query={graphql`
      query SiteTitleQuery {
        site {
                     siteMetadata {
            title
          }
        }
      }
    `}

Results in Loading (StaticQuery)

@audiolion
Copy link
Author

audiolion commented Aug 30, 2018

@cwgw thanks for doing some extra investigation 👍

edit: woops, misclicked the button

@audiolion audiolion reopened this Aug 30, 2018
@Chuloo
Copy link
Contributor

Chuloo commented Aug 31, 2018

Can you point to lines in your reproduction with the whitespaces? @audiolion

@Chuloo Chuloo added the status: awaiting author response Additional information has been requested from the author label Aug 31, 2018
@audiolion
Copy link
Author

audiolion commented Sep 1, 2018

@Chuloo I am not sure what you mean? The whitespace is in the query:

    query={graphql`
      query SiteData {
        site {
          siteMetadata {
            title
            description
            keywords
          }
        }
        allContentfulProject {
          edges {
            node {
              id
              name
              slug
            }
          }
        }
      }
    `}

// vs

    query={graphql`
  query SiteData {
    site {
      siteMetadata {
        title
        description
        keywords
      }
    }
    allContentfulProject {
      edges {
        node {
          id
          name
          slug
        }
      }
    }
  }
`}

@pieh pieh added type: bug An issue or pull request relating to a bug in Gatsby status: confirmed Issue with steps to reproduce the bug that’s been verified by at least one reviewer. and removed status: awaiting author response Additional information has been requested from the author labels Sep 3, 2018
@pieh
Copy link
Contributor

pieh commented Sep 3, 2018

I finally got some time to reproduce it. Will be following up with PR fixing that shortly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: confirmed Issue with steps to reproduce the bug that’s been verified by at least one reviewer. type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants