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

fix(gatsby): handle case of html and data files mismatch #34225

Merged
merged 13 commits into from
Dec 17, 2021

Conversation

pieh
Copy link
Contributor

@pieh pieh commented Dec 9, 2021

Description

If for whatever reason html content from old deploys gets loaded (some cases of browser cache), that old html will load old .js bundles. The page-data and app-data files will however be fetched for newest deploy. If there was webpack recompilation happening between those deploys issues might appear - such as js bundle expecting some static queries to be loaded by our loader, but they never do because new page-data files have different set of static queries to fetch. All of this can result in dreadful "The result of this StaticQuery could not be fetched" errors (when using useStaticQuery hook) or "Loading (StaticQuery)" placeholder text (for <StaticQuery> component).

Potential solution (implemented in this PR):

  • inline webpackCompilationHash in every html page
  • use that and compare it to hash from just fetched app-data.json file
  • if they don't match it should mean that our data files (such as app-data.json and page-data.json) were from different build and they might not be compatible. In that case try to reload (with extra step of checking if we just reloaded already to avoid infinite reload loop - if refresh didn't fix mismatch, then likely deploy in current shape is borked, so no point in trying it again and again)

Related Issues

Related to #33956

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Dec 9, 2021
@pieh pieh added topic: frontend Relates to frontend issues (e.g. reach/router, gatsby-link, page-loading, asset-loading, navigation) and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Dec 9, 2021
@pieh pieh force-pushed the fix/handle-html-out-of-sync-on-initial-render branch from 2f1e899 to f8d51f2 Compare December 9, 2021 12:07
@KyleAMathews
Copy link
Contributor

I like this a lot. This would handle both hosts that don't force validation on html files + service worker issues. Nice work!

@pieh pieh marked this pull request as ready for review December 14, 2021 13:15
@wardpeet wardpeet merged commit 97e942e into master Dec 17, 2021
@wardpeet wardpeet deleted the fix/handle-html-out-of-sync-on-initial-render branch December 17, 2021 15:18
@aaronadamsCA
Copy link
Contributor

I think this may solve #33112 as well.

@DSchau
Copy link
Contributor

DSchau commented Jan 13, 2022

@aaronadamsCA let us know if it does! Would be great to validate that hypothesis.

@aaronadamsCA
Copy link
Contributor

Might need to resolve #34484 before getting a read on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: frontend Relates to frontend issues (e.g. reach/router, gatsby-link, page-loading, asset-loading, navigation)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants