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

Don't prefetch the current page #2097

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

joetannenbaum
Copy link
Contributor

Here's the scenario:

  • User is on /users
  • There is a Link to /users that prefetches on hover on the page
  • If they hover that Link it will prefetch page and refresh the data on the current page
  • If there is any changed form state, etc it gets reset back to its original state

My solution is: if we are trying to prefetch the current page, just don't. I can't think of a scenario where this is useful, we're already on the page, so we just abort it before it even kicks off.

@joetannenbaum
Copy link
Contributor Author

Fixes: #2066

@Jussi-Mannisto
Copy link

Strict href comparison doesn't take fragments into account, e.g. /about#contact. These links would still get prefetched after this fix.

I used this comparison in my workaround:

function isCurrentPage(href) {
	const url = new URL(href, window.location.origin);
	const current = window.location;

	return url.origin + url.pathname + url.search === current.origin + current.pathname + current.search;
}

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.

2 participants