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

Static files changed content, but hash is the same (static query) - breaks website caches #26490

Closed
stevemarksd opened this issue Aug 16, 2020 · 6 comments
Labels
type: bug An issue or pull request relating to a bug in Gatsby

Comments

@stevemarksd
Copy link

stevemarksd commented Aug 16, 2020

Reading here https://www.gatsbyjs.com/docs/caching/#static-files says these files should be cached because never change contents. Well, it did.

I have a feeling is happening because the static query is outside the project directory, in node_modules and the hash is not refreshed or is not based on the contents.

It's very interesting that even if I clean the cache folder, the query is set to the same filename.

Changing the query itself changes the hash limit: 20 -> limit: 21

Description

I have this static query (in a node_module to another project. I got a common project for common gatsby stuff reused between many websites. So this file is not in my main project directly, is in node_modules)


export const RecentPosts: React.FC<{}> = () => {
  const data: Data = useStaticQuery(graphql`
    query {
      allMarkdownRemark(
        sort: { order: DESC, fields: [frontmatter___createdAt] }
        limit: 20
        filter: {frontmatter: {content: {eq:true}}}
      ) {
        edges {
          node {
            id
            excerpt(pruneLength: 250)
            frontmatter {
              updatedAt
              createdAt
              path
              title
              description
              keywords
            }
          }
        }
      }
    }
  `)
  return (
    <>
      <Ul>
        {data.allMarkdownRemark.edges.map((e, i) => {
          return (
            <Li key={i}>
            </Li>
          )
        })}
      </Ul>
    </>
  )
}

and is built to this file: static/d/3852913098.json

But the contents changed when I added a new post, but the file name is the same.

Steps to reproduce

See file above

Expected result

Create a new file with different hash

Actual result

Same hash

Environment


  System:
    OS: Windows 10 10.0.19***
    CPU: (12) x64 Intel(R) Core(TM) i7-****** CPU @ 3.70GHz
  Binaries:
    Node: 14.7.0 - ~\AppData\Local\Temp\ccc\node.CMD
    Yarn: 1.22.4 - ~\AppData\Local\Temp\ccc\yarn.CMD
    npm: 6.14.7 - C:\Program Files\nodejs\npm.CMD
  Languages:
    Python: 3.8.5
  Browsers:
    Chrome: 84.0.4147.***
    Edge: Spartan (44.19041.***.0)
  npmPackages:
    gatsby: ^2.21.9 => 2.24.26
    gatsby-image: ^2.4.0 => 2.4.14
    gatsby-plugin-catch-links: ^2.0.9 => 2.3.11
    gatsby-plugin-emotion: ^3.0.1 => 3.0.1
    gatsby-plugin-layout: ^1.3.0 => 1.3.10
    gatsby-plugin-manifest: ^2.0.12 => 2.4.21
    gatsby-plugin-material-ui: ^2.1.8 => 2.1.10
    gatsby-plugin-react-helmet: ^3.0.0 => 3.3.10
    gatsby-plugin-s3: ^0.3.4 => 0.3.4
    gatsby-plugin-sharp: ^2.0.15 => 2.6.24
    gatsby-plugin-sitemap: ^2.0.3 => 2.4.11
    gatsby-plugin-typescript: ^2.0.3 => 2.4.16
    gatsby-plugin-webpack-bundle-analyser-v2: ^1.1.9 => 1.1.11
    gatsby-remark-component: ^1.1.3 => 1.1.3
    gatsby-remark-images: ^3.0.1 => 3.3.24
    gatsby-source-filesystem: ^2.3.23 => 2.3.23
    gatsby-transformer-remark: ^2.1.15 => 2.8.27
    gatsby-transformer-sharp: ^2.1.9 => 2.5.12

Done in 2.53s.

@stevemarksd stevemarksd added the type: bug An issue or pull request relating to a bug in Gatsby label Aug 16, 2020
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Aug 16, 2020
@KyleAMathews
Copy link
Contributor

Hey sorry you're hitting this. This was fixed a little while ago in #26242 — could you try upgrading to the latest?

@stevemarksd
Copy link
Author

perfect, thanks. I will try and update.

@stevemarksd
Copy link
Author

stevemarksd commented Aug 16, 2020

image

So seems to have moved in another folder, but hash is the same. I upgraded to 2.24.47 latest on npm https://www.npmjs.com/package/gatsby

That fix has been pushed on gatsby@2.24.33 so I guess bug still persists. Maybe we can reopen this issue?

@KyleAMathews
Copy link
Contributor

For files in that folder, the caching rules is that the browser revalidates on every request like with page query data. So you shouldn't see problems with stale content.

@stevemarksd
Copy link
Author

Ah, so the fix didn't change the hash based on contents... Are you planning to ever convert to hash based on contents?

@LekoArts LekoArts removed the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Aug 25, 2020
@Sherry-hue
Copy link

I encountered the same problem, I think hash value should be set according to the content of JSON, rather than never change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

No branches or pull requests

4 participants