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

how to use disableCorePrefetching? true or false? #9827

Closed
TylerBarnes opened this issue Nov 8, 2018 · 3 comments · Fixed by #9852
Closed

how to use disableCorePrefetching? true or false? #9827

TylerBarnes opened this issue Nov 8, 2018 · 3 comments · Fixed by #9852
Labels
good first issue Issue that doesn't require previous experience with Gatsby help wanted Issue with a clear description that the community can help with. type: documentation An issue or pull request for improving or updating Gatsby's documentation

Comments

@TylerBarnes
Copy link
Contributor

Summary

I'm building a starter/plugin that allows for previewing changes in a WordPress source gatsby site. I'm generating a preview version of the site to be used by WP and I want to disable prefetching since I'm also going to disable navigation from previews. The docs are a little unclear on how to use this api. When I just return true or false to it, it breaks. If I return a function which returns a bool, it doesn't say anything.

I'm wondering if I should be returning true or false or something else entirely.

Thanks!

@kakadiadarpan
Copy link
Contributor

@TylerBarnes Please check the below code snippet where disableCorePrefetching is being used. It is exporting a function which returns a boolean

const { guess } = require(`guess-webpack/api`)
exports.disableCorePrefetching = () => true
let initialPath
let notNavigated = true
exports.onRouteUpdate = ({ location }) => {
if (initialPath !== location.pathname) {
notNavigated = false
return
}
initialPath = location.pathname
}
exports.onPrefetchPathname = ({ getResourcesForPathname }, pluginOptions) => {
if (process.env.NODE_ENV !== `production`) return
const matchedPaths = Object.keys(
guess({
path: window.location.pathname,
threshold: pluginOptions.minimumThreshold,
})
)
// Don't prefetch from client for the initial path as we did that
// during SSR
if (!(notNavigated && initialPath === window.location.pathname))
matchedPaths.forEach(getResourcesForPathname)
}

@kakadiadarpan kakadiadarpan added the type: question or discussion Issue discussing or asking a question about Gatsby label Nov 9, 2018
@kakadiadarpan
Copy link
Contributor

Also, would you like to raise a PR to fix the documentation for the same? I would be happy to help you out if you are interested.

@kakadiadarpan kakadiadarpan added help wanted Issue with a clear description that the community can help with. type: documentation An issue or pull request for improving or updating Gatsby's documentation good first issue Issue that doesn't require previous experience with Gatsby and removed type: question or discussion Issue discussing or asking a question about Gatsby labels Nov 9, 2018
@TylerBarnes
Copy link
Contributor Author

I'll make a PR for sure!

pieh pushed a commit that referenced this issue Nov 10, 2018
<!--
  Q. Which branch should I use for my pull request?
  A. Use `master` branch (probably).

  Q. Which branch if my change is a bug fix for Gatsby v1?
  A. In this case, you should use the `v1` branch

  Q. Which branch if I'm still not sure?
  A. Use `master` branch. Ask in the PR if you're not sure and a Gatsby maintainer will be happy to help :)

  Note: We will only accept bug fixes for Gatsby v1. New features should be added to Gatsby v2.

  Learn more about contributing: https://www.gatsbyjs.org/docs/how-to-contribute/
-->
This closes #9827
gpetrioli pushed a commit to gpetrioli/gatsby that referenced this issue Jan 22, 2019
<!--
  Q. Which branch should I use for my pull request?
  A. Use `master` branch (probably).

  Q. Which branch if my change is a bug fix for Gatsby v1?
  A. In this case, you should use the `v1` branch

  Q. Which branch if I'm still not sure?
  A. Use `master` branch. Ask in the PR if you're not sure and a Gatsby maintainer will be happy to help :)

  Note: We will only accept bug fixes for Gatsby v1. New features should be added to Gatsby v2.

  Learn more about contributing: https://www.gatsbyjs.org/docs/how-to-contribute/
-->
This closes gatsbyjs#9827
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Issue that doesn't require previous experience with Gatsby help wanted Issue with a clear description that the community can help with. type: documentation An issue or pull request for improving or updating Gatsby's documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants