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-link): don't prefetch same page #28307

Merged
merged 4 commits into from Nov 26, 2020

Conversation

wardpeet
Copy link
Contributor

@wardpeet wardpeet commented Nov 26, 2020

Description

When prefetching a url that's already being fetched can end up in a race-condition where the browser looks into it's prefetch cache.
You can end up with stale data.

How can this happen?
If you have a gatsby-link component with the same url as the current page.

This is an issue when using wordpress preview

I've added tests to make sure we test this behaviour

On the demo you see that the prefetch cached network request wins over the new request
wordpress preview bug

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Nov 26, 2020
@LekoArts LekoArts removed the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Nov 26, 2020
@TylerBarnes
Copy link
Contributor

This looks great! Thanks for doing this so quickly @wardpeet !

Copy link
Contributor

@TylerBarnes TylerBarnes left a comment

Choose a reason for hiding this comment

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

Looks cleaner, more dry with _prefetch() and appears that it will solve the bug 😄 Woo 🎉

@TylerBarnes
Copy link
Contributor

@wardpeet is there a way to fast track the release of this in the new release process? Since it's related to a P1 it'd be great to be able to ship this soon. cc @smthomas

@wardpeet
Copy link
Contributor Author

We can hotfix it :)

@wardpeet wardpeet merged commit 3666130 into gatsbyjs:master Nov 26, 2020
@wardpeet wardpeet deleted the fix/wordpress-preview-cache branch November 26, 2020 18:53
@TylerBarnes
Copy link
Contributor

Awesome :D

@wardpeet wardpeet added this to To cherry-pick in V2 Release hotfixes via automation Nov 26, 2020
pieh pushed a commit that referenced this pull request Nov 26, 2020
* fix(gatsby-link): don't prefetch same page

* test prefect intersection-observer

Co-authored-by: gatsbybot <mathews.kyle+gatsbybot@gmail.com>
pieh pushed a commit that referenced this pull request Nov 26, 2020
* fix(gatsby-link): don't prefetch same page

* test prefect intersection-observer

Co-authored-by: gatsbybot <mathews.kyle+gatsbybot@gmail.com>
(cherry picked from commit 3666130)
@pieh
Copy link
Contributor

pieh commented Nov 26, 2020

@wardpeet, @TylerBarnes PR backporting this to 2.27 release - #28313

vladar pushed a commit that referenced this pull request Nov 26, 2020
* fix(gatsby-link): don't prefetch same page

* test prefect intersection-observer

Co-authored-by: gatsbybot <mathews.kyle+gatsbybot@gmail.com>
(cherry picked from commit 3666130)

Co-authored-by: Ward Peeters <ward@coding-tech.com>
@vladar vladar moved this from To cherry-pick to Backported in V2 Release hotfixes Nov 26, 2020
@vladar
Copy link
Contributor

vladar commented Nov 26, 2020

Published in gatsby-link@2.6.1, gatsby@2.27.4

@TylerBarnes
Copy link
Contributor

Thanks @vladar !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

5 participants