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-plugin-offline): gracefully degrade if appshell isn't precached #10329

Merged
merged 2 commits into from
Dec 6, 2018

Conversation

pieh
Copy link
Contributor

@pieh pieh commented Dec 6, 2018

It's not clear what cause app shell to not be succesfully precached and this is hot fix to fix serving blank page with following error in console:
The FetchEvent for "<url>" resulted in a network error response: an object that was not a Response was passed to respondWith().

Ideally we would try to push that offline appshell to precache in this case. Fix in this PR will only work when people are online

/cc @davidbailey00

Copy link
Contributor

@DSchau DSchau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Let's get this merged

Copy link
Contributor

@vtenfys vtenfys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only concern is that someone could visit a page while the offline shell is downloading, but then because they loaded another page first, we've prevented the shell from being served even if it was almost downloaded.

For this reason I think it would be better to not have a failedToGrabAppShell variable so that we allow it to retry later - in fact, it would be best to replace return fetch(event.request) with a fetch to the offline shell (it will be auto-cached upon successful load).

@pieh
Copy link
Contributor Author

pieh commented Dec 6, 2018

So I introduced a bit of then monster, it would be a lot nicer with async/await there, but for that we would need to adjust build process for package which is out of the scope of this PR.

Changes I've made:
If app shell is not in precache (for whatever reason) - try to fetch it. If we fetch successfully - put it in precache for any future requests so we can use happy path again. If we can't fetch app shell - fallback to fetching actual html content of the page.

Huge thanks to @davidbailey00 for help on this one!

@pieh pieh merged commit 19e9f3e into gatsbyjs:master Dec 6, 2018
@pieh pieh deleted the offline-error-handling branch December 6, 2018 22:37
m-allanson added a commit to kaoDev/gatsby that referenced this pull request Dec 7, 2018
* master: (870 commits)
  fix(graphql-skip-limit): declare `graphql` peer dependency (gatsbyjs#10305)
  fix(gatsby-plugin-offline): gracefully degrade if appshell isn't precached (gatsbyjs#10329)
  Service workers note (gatsbyjs#10276)
  fix(docs): link fixes, podcast addition (gatsbyjs#10332)
  feat(docs): Create clearer pathways in docs (gatsbyjs#9898)
  feat(www): Rename community section to creators (gatsbyjs#10312)
  docs(graphql-reference): clarify filtering using comma/and operator (gatsbyjs#10321)
  chore(release): Publish
  feat(gatsby-plugin-sass): Support Dart SASS (gatsbyjs#10159)
  fix(gatsby-source-drupal): use basic auth credentials to fetch remote files as well. (gatsbyjs#10302)
  fix(gatsby-source-filesystem): allow empty password for basic auth in createRemoteFileNode (gatsbyjs#10280)
  docs(gatsby-remark-prismjs): Use Gatsby V2 project structure (gatsbyjs#10059)
  chore: update link for react-gatsby-firebase-authentication (gatsbyjs#10314)
  fix(www): Awesome Gatsby sidebar link (gatsbyjs#10313)
  Add thijs koerselman to creators list (gatsbyjs#10303)
  chore(release): Publish
  fix(gatsby-plugin-emotion): allow for React.Fragment shorthand syntax (gatsbyjs#10291)
  feat(www): Update starter cards (gatsbyjs#10258)
  Update index.md (gatsbyjs#10307)
  Update index.md (gatsbyjs#10306)
  ...
m-allanson added a commit that referenced this pull request Dec 8, 2018
* master: (1421 commits)
  feat(gatsby-image): add onStartLoad prop  (#6702)
  fix(docs): add Ecosystem to docs sidebar, consistency with tutorial sidebar (#10350)
  fix(www): Starters.yaml housekeeping (#10354)
  docs: add ttag starter (#10352)
  docs: document branching (#9983)
  plugin checker initial commit (#7062)
  docs: new starter features is required (#10353)
  docs: migrated line highlighting to highlight-line, highlight-start, highlight-end (#10202)
  Add Birra Napoli to site showcase (#10344)
  Add BetterDocs to site showcase (#10349)
  chore(release): Publish
  Add option to keep metadata in files processed by `gatsby-plugin-sharp` (#10210)
  fix(gatsby): [loki] sync db autosaves (#10212)
  Add Ad Hoc Homework to sites.yml (#10346)
  fix(graphql-skip-limit): declare `graphql` peer dependency (#10305)
  fix(gatsby-plugin-offline): gracefully degrade if appshell isn't precached (#10329)
  Service workers note (#10276)
  fix(docs): link fixes, podcast addition (#10332)
  feat(docs): Create clearer pathways in docs (#9898)
  feat(www): Rename community section to creators (#10312)
  ...
m-allanson pushed a commit that referenced this pull request Dec 11, 2018
fixes #10151

Issue in `gatsby-plugin-offline` was fixed in #10329, but gatsbyjs.org didn't upgrade.
gpetrioli pushed a commit to gpetrioli/gatsby that referenced this pull request Jan 22, 2019
…ached (gatsbyjs#10329)

If app shell is not in precache (for whatever reason) - try to fetch it. If we fetch successfully - put it in precache for any future requests so we can use happy path again. If we can't fetch app shell - fallback to fetching actual html content of the page.
gpetrioli pushed a commit to gpetrioli/gatsby that referenced this pull request Jan 22, 2019
fixes gatsbyjs#10151

Issue in `gatsby-plugin-offline` was fixed in gatsbyjs#10329, but gatsbyjs.org didn't upgrade.
@pieh pieh restored the offline-error-handling branch May 17, 2020 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants