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] Ignore click event if href is mailto link #4072

Merged
merged 4 commits into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tiny-badgers-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Ignore click event if url does not have origin (e.g. `mailto:`, `tel:`)
8 changes: 7 additions & 1 deletion packages/kit/src/runtime/client/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,19 @@ export class Router {

if (!a.href) return;

const is_svg_a_element = a instanceof SVGAElement;
const url = get_href(a);
const url_string = url.toString();
if (url_string === location.href) {
if (!location.hash) event.preventDefault();
return;
}

// Ignore if url does not have origin (e.g. `mailto:`, `tel:`.)
// MEMO: Without this condition, firefox will open mailer twice.
// See: https://github.com/sveltejs/kit/issues/4045
if (!is_svg_a_element && url.origin === 'null') return;

// Ignore if tag has
// 1. 'download' attribute
// 2. 'rel' attribute includes external
Expand All @@ -197,7 +203,7 @@ export class Router {
}

// Ignore if <a> has a target
if (a instanceof SVGAElement ? a.target.baseVal : a.target) return;
if (is_svg_a_element ? a.target.baseVal : a.target) return;

// Check if new url only differs by hash and use the browser default behavior in that case
// This will ensure the `hashchange` event is fired
Expand Down