-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
[gatsby-plugin-offline] [gatsby/cache-dir] Fix various offline and caching issues #7355
Conversation
Deploy preview for using-postcss-sass failed. Built with commit 4eb02cd https://app.netlify.com/sites/using-postcss-sass/deploys/5b75433b3813f010edac0916 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great! Very through! I'll give it a more through review, hopefully later, but thanks!
@@ -1,7 +1,7 @@ | |||
{ | |||
"name": "gatsby-plugin-offline", | |||
"description": "Gatsby plugin which sets up a site to be able to run offline", | |||
"version": "2.0.0-beta.9", | |||
"version": "2.0.0-beta.10", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the version gets bumped automatically as part of deploys so please remove this
Deploy preview for using-drupal ready! Built with commit 4eb02cd |
Deploy preview for gatsbygram ready! Built with commit 4eb02cd |
Deploy preview for image-processing failed. Built with commit 03138384e2592f0abca8626f22822d4fd213215e https://app.netlify.com/sites/image-processing/deploys/5b7764dac6aed6786a016d16 |
@KyleAMathews thanks! I'd normally agree with small PRs, but the bugs were all so interdependent that I felt they would become fragmented with separate PRs, which might result in some of them reappearing after others having been fixed or some being forgotten. Looking forward to your full review though! |
Deploy preview for gatsbyjs failed. Built with commit 15ee192 https://app.netlify.com/sites/gatsbyjs/deploys/5b745f394ed62f238b914384 |
Deploy preview for gatsbyjs failed. Built with commit 4eb02cd https://app.netlify.com/sites/gatsbyjs/deploys/5b75433a3813f010edac090a |
Update: Update 2: I'll need a bit more time to get this fixed - should be ready later today |
@davidbailey00: Nice! ❤️ @jlengstorf: A lot going on here, but some of it may address some or even all of the things pertaining to |
@wKovacs64 I... definitely did not create that issue. I still have it written in my notebook to capture. 😬 Thanks for the heads up! |
@jlengstorf Oh no sweat, no rush. Thanks! |
I've fixed the remaining issues with regards to 404 pages, including a bug which #7268 introduced, and I've updated the changelog to reflect these fixes. Code should now be ready for a review! 😄 |
Just pushed a commit which throws an error if the sw.js patch fails - otherwise this might stop working in the future without users knowing why a problem is occurring. |
Not necessarily for this PR but it'd be great to add this in the future #7382 |
It wasn't a problem of azure, because it is a server as a static website. The problem only happened when in the production build served by Azure. It never happened on the local build. @davidbailey00 I'm uploading the public folder because I use it to make a continuous deployment using my GitHub repo. It's fixed, but it was a weird bug generated in the last update. |
@KyleAMathews @ssmith-wombatweb @dfmarulanda @jlengstorf perhaps we could have a runtime console warning after On the note of this, I just noticed that URL search queries aren't always kept when redirecting to
|
Yeah, that's the sort of warning I was thinking of. |
@KyleAMathews Alright, I'm still doing work experience until the end of this week but I can try fixing that tomorrow evening, along with the other bug. A warning should be easy to implement, although the bug I just discovered might take me a bit longer - it only happens from external links or direct URL entry, not from (Also, unrelated to these issues but the company I'm doing work exp at seems impressed by Gatsby and is considering rewriting their current sites on legacy stacks using it 😄) |
Just coming back to confirm that changing that to lowercase solves my issues on Netlify. |
I've thought of a better solution than showing a warning - we can use Gatsby's global |
Nice! :-D |
Just to update everyone, I've made some progress on this by replacing Edit: I meant RouteHandler rather than PageRenderer |
cc @KyleAMathews @jlengstorf @m-allanson I'm really struggling to understand where If I log the props... ...it's clear that the But after running a trace I still have no idea how it gets these props. The element itself is created at line 126 (in my local code with added ...since it renders All function calls between line 126 and the All the other calls are higher-level and have no mention of |
@davidbailey00 could you copy your previous comments over to a new issue? This one is getting rather lengthy :-) |
@KyleAMathews sure, in hindsight I probably should've done that earlier :) |
I updated gatsby today and now im getting
|
@dfmarulanda Thanks for the heads up, I'll check this out. |
@dfmarulanda hm, I'm unable to see what the issue is here since everything works locally for me... Can you try upgrading all packages again, and running |
I already deleted node_modules and then yarn install. Also tried to add @babel/runtime by itself. {
"private": true,
"scripts": {
"build": "gatsby build",
"develop": "gatsby develop",
"lint:es": "eslint --ignore-path .gitignore \"**/*.{js,jsx}\"",
"lint:style": "stylelint \"src/**/*.scss\"",
"lint": "yarn lint:es && yarn lint:style",
"format": "prettier-eslint --write \"**/*.{js,jsx,json,css,scss,md}\""
},
"dependencies": {
"@babel/runtime": "^7.0.0",
"@reach/router": "^1.1.1",
"babel-eslint": "^8.2.6",
"babel-plugin-styled-components": "^1.5.1",
"fbjs": "^0.8.17",
"gatsby": "^2.0.0-rc.7",
"gatsby-plugin-canonical-urls": "^2.0.0-rc.1",
"gatsby-plugin-drift": "^1.0.0",
"gatsby-plugin-favicon": "^3.1.2",
"gatsby-plugin-offline": "2.0.0-rc.0",
"gatsby-plugin-react-helmet": "^3.0.0-rc.1",
"gatsby-plugin-styled-components": "^3.0.0-rc.1",
"gatsby-plugin-typography": "^2.2.0-rc.2",
"grid-styled": "^5.0.2",
"object-assign": "^4.1.1",
"prop-types": "^15.6.2",
"react": "^16.4.2",
"react-dom": "^16.4.2",
"react-emotion": "^9.2.4",
"react-helmet": "^5.2.0",
"react-router-dom": "^4.3.1",
"react-typography": "^0.16.13",
"styled-components": "^3.4.5",
"styled-media-query": "^2.0.2",
"typography": "^0.16.17"
},
"devDependencies": {
"emotion": "^9.2.6",
"eslint": "^4.19.1",
"eslint-config-airbnb": "^17.0.0",
"eslint-plugin-import": "^2.13.0",
"eslint-plugin-jsx-a11y": "^6.1.1",
"eslint-plugin-react": "^7.10.0",
"prettier-eslint-cli": "^4.7.0",
"stylelint": "^9.4.0",
"stylelint-config-idiomatic-order": "^5.0.0",
"stylelint-config-recommended-scss": "^3.0.0",
"stylelint-scss": "^3.2.0",
"webpack": "^4.16.4",
"webpack-cli": "^3.1.0"
}
} |
Yeah. It seems it was the problem. Thanks! |
I made an update yesterday and it seems it's broken again. I cannot figure out what's happening with it. You can check out my website at https://crowdswap.com |
@dfmarulanda can you create new issue with more details of your setup - including output from |
@pieh actually I'm just checking this out and the problem seems to be because the |
@dfmarulanda I've just checked and confirmed my above comment - you're not ignoring the Also, as @pieh said, in the future please create a new issue since GitHub's TTFB on this page is getting ridiculous 😀 |
But i don't understand why i have to gitignore the public folder. I use it as continous deployment to my website using azure web apps. I always delete the public folder before publishing. Why it would be the problem? PD. Azure is connected with my public folder in my github repo. |
Your HTML file is referencing JSON resources which don't exist on the server: This is causing Gatsby to think that it shouldn't handle the page, since it can't find the resources, and so it tries loading the page directly. Since Gatsby does actually handle the page, it does the same thing again and again, forever.
In that case I think you're doing something wrong - after I ran |
OK. I'll try to change my deploy process. It's super easy to do it using netlify, aws, heroku, but there is no an azure plugin. There is a docker plugin working in the latest version of Gatsby? |
Changes made:
<div>
is replaced with<span>
in gatsby-plugin-offline'sapp-shell.js
to prevent an edge case in Chrome, where the the outer element's class attribute is unset despite its className being set in the VDOM, if the page was loaded from the offline shell.getResourcesForPathname
was fixed - previously this prevented later code from calling sincePromise.all(pathnameResources)
would never resolve.pageResources
.get-resources-from-html.js
.get-resources-from-html.js
is modified so that if a custom 404 page doesn't exist, an empty array will be returned.getResourcesFromHTML
, causing errors to occur when trying to navigate to another page when offline (if they haven't all been cached).navigateFallbackWhitelist
regex is modified to prevent loading the offline shell if the URL ends with?no-cache=1
or&no-cache=1
.sw.js
is patched to include search queries when matching URLs againstnavigateFallbackWhitelist
. Unfortunately I couldn't find any options to enable this, so patching appears to be the only way until a change is made upstream.ignoreUrlParametersMatching
options, but it's for ignoring differences, e.g. between/page/
and/page/?utm_source=github
, not for disabling caching or fallback.page-renderer.js
now checks forthis.state.pageResources.json
, since errors were previously occurring even whenthis.state.pageResources
existed due to the missing JSON data./admin/
for CMS, which is not directly part of Gatsby).production-app.js
to prevent the 404 showing until an attempt has been made to load the page directlyonServiceWorkerInstalled
is now delayed by 100ms, since it was being called before thefetch
event listeners were added, thus preventing resources from being cached. Unfortunately I couldn't find a programmatic way to do this (other than more patching ofsw.js
, which is less than ideal).checkIfDoingInitialRenderForSW
is removed fromloader.js
as it was causing the SW to be removed when navigating to a nonexistent page, even if the website had not been updated, causing it to stop working offline entirely - regardless, it is no longer needed with the other changes made.Closes #6212, Closes #7053, Closes #6688, possibly others