Skip to content

Commit

Permalink
Turbo v8.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
afcapel committed Feb 9, 2024
1 parent ef4a624 commit 4761602
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 48 deletions.
72 changes: 37 additions & 35 deletions app/assets/javascripts/turbo.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
Turbo 8.0.1
Turbo 8.0.2
Copyright © 2024 37signals LLC
*/
(function(prototype) {
Expand Down Expand Up @@ -2647,9 +2647,6 @@ class LinkPrefetchObserver {
if (turboFrameTarget && turboFrameTarget !== "_top") {
request.headers["Turbo-Frame"] = turboFrameTarget;
}
if (link.hasAttribute("data-turbo-stream")) {
request.acceptResponseType(StreamMessage.contentType);
}
}
requestSucceededWithResponse() {}
requestStarted(fetchRequest) {}
Expand All @@ -2662,41 +2659,46 @@ class LinkPrefetchObserver {
}
#isPrefetchable(link) {
const href = link.getAttribute("href");
if (!href || href.startsWith("#") || link.getAttribute("data-turbo") === "false" || link.getAttribute("data-turbo-prefetch") === "false") {
return false;
}
const event = dispatch("turbo:before-prefetch", {
target: link,
cancelable: true
});
if (event.defaultPrevented) {
return false;
}
if (link.origin !== document.location.origin) {
return false;
}
if (![ "http:", "https:" ].includes(link.protocol)) {
return false;
}
if (link.pathname + link.search === document.location.pathname + document.location.search) {
return false;
}
const turboMethod = link.getAttribute("data-turbo-method");
if (turboMethod && turboMethod !== "get") {
return false;
}
if (targetsIframe(link)) {
return false;
}
const turboPrefetchParent = findClosestRecursively(link, "[data-turbo-prefetch]");
if (turboPrefetchParent && turboPrefetchParent.getAttribute("data-turbo-prefetch") === "false") {
return false;
}
if (!href) return false;
if (unfetchableLink(link)) return false;
if (linkToTheSamePage(link)) return false;
if (linkOptsOut(link)) return false;
if (nonSafeLink(link)) return false;
if (eventPrevented(link)) return false;
return true;
}
}

const targetsIframe = link => !doesNotTargetIFrame(link);
const unfetchableLink = link => link.origin !== document.location.origin || ![ "http:", "https:" ].includes(link.protocol) || link.hasAttribute("target");

const linkToTheSamePage = link => link.pathname + link.search === document.location.pathname + document.location.search || link.href.startsWith("#");

const linkOptsOut = link => {
if (link.getAttribute("data-turbo-prefetch") === "false") return true;
if (link.getAttribute("data-turbo") === "false") return true;
const turboPrefetchParent = findClosestRecursively(link, "[data-turbo-prefetch]");
if (turboPrefetchParent && turboPrefetchParent.getAttribute("data-turbo-prefetch") === "false") return true;
return false;
};

const nonSafeLink = link => {
const turboMethod = link.getAttribute("data-turbo-method");
if (turboMethod && turboMethod.toLowerCase() !== "get") return true;
if (isUJS(link)) return true;
if (link.hasAttribute("data-turbo-confirm")) return true;
if (link.hasAttribute("data-turbo-stream")) return true;
return false;
};

const isUJS = link => link.hasAttribute("data-remote") || link.hasAttribute("data-behavior") || link.hasAttribute("data-confirm") || link.hasAttribute("data-method");

const eventPrevented = link => {
const event = dispatch("turbo:before-prefetch", {
target: link,
cancelable: true
});
return event.defaultPrevented;
};

class Navigator {
constructor(delegate) {
Expand Down
12 changes: 6 additions & 6 deletions app/assets/javascripts/turbo.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/javascripts/turbo.min.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hotwired/turbo-rails",
"version": "8.0.1",
"version": "8.0.2",
"description": "The speed of a single-page web application without having to write any JavaScript",
"module": "app/javascript/turbo/index.js",
"main": "app/assets/javascripts/turbo.js",
Expand All @@ -13,7 +13,7 @@
"release": "npm publish && git commit -am \"$npm_package_name v$npm_package_version\" && git push"
},
"dependencies": {
"@hotwired/turbo": "^8.0.1",
"@hotwired/turbo": "^8.0.2",
"@rails/actioncable": "^7.0"
},
"devDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
chalk "^2.4.2"
js-tokens "^4.0.0"

"@hotwired/turbo@^8.0.1":
version "8.0.1"
resolved "https://registry.yarnpkg.com/@hotwired/turbo/-/turbo-8.0.1.tgz#0f4be48f43e96237181b31879258498b9f0d15d6"
integrity sha512-6DdRoFV8p1qM2YxieZ0McSzFfdKHH85FQn3C8UpLDgyD1UDb3ERhUsXg65M6nPuZeHtBZLY4hUumMdaAP0N1+w==
"@hotwired/turbo@^8.0.2":
version "8.0.2"
resolved "https://registry.yarnpkg.com/@hotwired/turbo/-/turbo-8.0.2.tgz#c31cdadfe66b98983066a94073b26fc7e15835f0"
integrity sha512-3K6QZkwWfosAV8zuM5bY+kKF02jp1lMQGsWfSE6wXdZBRBP3ah+Vj26YNqYtkEomBwRWA0QKhZgyJP7xOQkVEg==

"@jridgewell/gen-mapping@^0.3.0":
version "0.3.3"
Expand Down

0 comments on commit 4761602

Please sign in to comment.