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

Pages rebuilt when no code or content has changed due to non-deterministic hashes #22964

Closed
peteris opened this issue Apr 9, 2020 · 2 comments · Fixed by #22965
Closed

Pages rebuilt when no code or content has changed due to non-deterministic hashes #22964

peteris opened this issue Apr 9, 2020 · 2 comments · Fixed by #22965
Labels
type: bug An issue or pull request relating to a bug in Gatsby

Comments

@peteris
Copy link
Contributor

peteris commented Apr 9, 2020

Description

When using the experimental page build optimisation (GATSBY_EXPERIMENTAL_PAGE_BUILD_ON_DATA_CHANGES=true), the webpack hash is not deterministic, resulting in unnecessary rebuilds.

This is due to the fact that the pages are not always emitted in the same order, causing the keys in .cache/async-requires.js to be written in a different order and producing a different hash for the module, and therefore the build.

Steps to reproduce

  1. Using the starter with issue reproduction below, and run the build:
$ GATSBY_EXPERIMENTAL_PAGE_BUILD_ON_DATA_CHANGES=true npm run build -- --log-pages
  1. Run the build again a few times.

Gatsby starter with minimal reproduction:
https://github.com/peteris/gatsby-bug-repro-non-deterministic-builds

Expected result

Since no code or content has changed, the build hash should not change and no pages should be emitted.

Actual result

Pages are still periodically emitted. This is due to the fact that the pages are not always emitted in the same order, causing the keys in .cache/async-requires.js to be written in a different order and producing a different hash for the module, and the build.

Potential solution

I believe all we need to do is sort the keys in this function.

// before
.uniqBy(c => c.componentChunkName)

// after
.uniqBy(c => c.componentChunkName)
.orderBy(c => c.componentChunkName) 

I'm happy to open a PR if a maintainer can +1 this idea.

Environment

System:
OS: macOS 10.15.4
CPU: (8) x64 Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 12.6.0 - ~/.nave/installed/12.6.0/bin/node
npm: 6.9.0 - ~/.nave/installed/12.6.0/bin/npm
Languages:
Python: 2.7.16 - /usr/bin/python
Browsers:
Chrome: 80.0.3987.163
Safari: 13.1
npmPackages:
gatsby: ^2.20.12 => 2.20.12

@peteris peteris added the type: bug An issue or pull request relating to a bug in Gatsby label Apr 9, 2020
@pieh
Copy link
Contributor

pieh commented Apr 9, 2020

I started writing reply suggesting exactly same solution that you did, before realizing you provided it. So definitely "+1" on your solution and pull request like is more than welcome

@peteris
Copy link
Contributor Author

peteris commented Apr 9, 2020

Thanks @pieh , I've opened #22965

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

Successfully merging a pull request may close this issue.

2 participants