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

Conditional page builds not working with static queries #25928

Closed
herecydev opened this issue Jul 21, 2020 · 5 comments · Fixed by #32949
Closed

Conditional page builds not working with static queries #25928

herecydev opened this issue Jul 21, 2020 · 5 comments · Fixed by #32949
Assignees
Labels
status: needs core review Currently awaiting review from Core team member type: bug An issue or pull request relating to a bug in Gatsby

Comments

@herecydev
Copy link
Contributor

#25723 has moved static queries outside of the js bundles. Previously a change to these would trigger a full rebuild which wasn't ideal. The changes made have fixed this, however now nothing is triggering so it is not possible to detect and deploy a static query change.

This effectively makes them unreliable for use with conditional page builds

@herecydev herecydev added the type: bug An issue or pull request relating to a bug in Gatsby label Jul 21, 2020
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Jul 21, 2020
@madalynrose madalynrose added status: needs core review Currently awaiting review from Core team member and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Jul 21, 2020
@SpicyPete
Copy link

I am also having this issue, where any template with a static query being exported fails to build... which are most of my pages in some projects.

@StuartRayson
Copy link
Contributor

StuartRayson commented Aug 14, 2020

This is a good change having the static queries outside of the JS bundles🙇 . The full rebuild on the static data change wasn't ideal, in the first attempt we struggled linking page paths to its static data.

Just thinking how to we could go about fixing conditional page builds 🤔 . I haven't started investigating myself yet, so just a few questions.

I see in the PR (#25723) there is now a staticQueryResults with a path, is the staticQueryResults saved in the redux.state cache?

Do the staticQueryHashes change if query data returned is different?

@herecydev
Copy link
Contributor Author

@sidharthachatterjee @KyleAMathews can this get some love? I know you spruced up conditional page builds in V3 but this is still an outstanding issue that makes static queries worthless at the moment.

@KyleAMathews
Copy link
Contributor

We have tests that static queries get re-run when their data changes — https://github.com/gatsbyjs/gatsby/blob/master/integration-tests/artifacts/src/pages/static-query-result-tracking/should-invalidate.js

Could you make a reproduction of what you're seeing so we can dig in more?

@herecydev
Copy link
Contributor Author

Struggling to recreate in isolation, so appreciate that's not a great start. However I did dig into some of the dirty checking that Gatsby is doing and would really appreciate if you can look over my findings:

I added some additional logging into this block in redux/reducers/html.ts so that I could check if it detects that my static query data has changed. This works as intended:

Untitled

Gatsby detects the change, flags the query as dirty and subsequently rebuilds the necessary pages. The problem, I think, is that it's not correctly reupdating this entry in the trackedStaticQueryResults, so of course the old cache remains in the html. When the state is saved in saveState, the following can be observed:

Untitled2

So the old hash is persisted, and the following problem is introduced:

  1. data was "foo" in cache
  2. data changes to "bar"
  3. dirty detected and rebuilds pages
  4. data changes back to "foo"
  5. dirty is not detected because cached version is still "foo"
  6. No rebuild happens

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs core review Currently awaiting review from Core team member 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.

6 participants