-
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
fix(gatsby-plugin-offline): delay adding resources for paths until we have urls #8613
fix(gatsby-plugin-offline): delay adding resources for paths until we have urls #8613
Conversation
This is called when the "prefetching" has started not when the resources has actually been downloaded. Can you explain more about the error plugin-offline is causing? |
@KyleAMathews We need to guarantee that With the new API, it's called at a time when |
@@ -69,6 +73,8 @@ exports.onPrefetchPathname = ({ pathPrefix }, pluginOptions) => { | |||
resources.push(`static/d/${___dataPaths[page.jsonName]}.json`) | |||
// TODO add support for pathPrefix | |||
resources.forEach(r => prefetch(`/${r}`)) | |||
|
|||
onPostPrefetchPathname({ pathname: p }) |
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.
Could we refactor this a bit so loader.js
exposes prefetchResourcesForPath
function and guess
plugin and default gatsby prefetching use same implementation (and onPostPrefetchPathname
api is called just from loader.js
) ?
…fetching-resources-after-preload
Also make it easier to read by removing some unnecessary lines and changing indentation
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.
Thanks @davidbailey00!
This adds a new API called
onPostPrefetchPathname
, which runs after resources have been fetched for a pathname, as opposed toonPrefetchPathname
which runs directly upon fetching resources.In plugin-offline, the existing API
onPrefetchPathname
was being used - this was causing problems, since the resources weren't always fetched in time forgetResourceURLsForPathname
to return the data (see https://github.com/gatsbyjs/gatsby/pull/8613/files#diff-450f89b4ad11867864b3d8d21f83e442R35 - getResourceURLsForPathname sometimes returned null).Now that the API
onPostPrefetchPathname
is used instead,getResourceURLsForPathname
will always work properly, since the API runs after the resources are fetched and only if they are fetched successfully.In addition to this, I've passed
onPostPrefetchPathname
into the API runner foronPrefetchPathname
so that plugins which use custom prefetching can run this API at the right time.