Skip to content

Commit 4761602

Browse files
committed
Turbo v8.0.2
1 parent ef4a624 commit 4761602

File tree

5 files changed

+50
-48
lines changed

5 files changed

+50
-48
lines changed

app/assets/javascripts/turbo.js

+37-35
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
Turbo 8.0.1
2+
Turbo 8.0.2
33
Copyright © 2024 37signals LLC
44
*/
55
(function(prototype) {
@@ -2647,9 +2647,6 @@ class LinkPrefetchObserver {
26472647
if (turboFrameTarget && turboFrameTarget !== "_top") {
26482648
request.headers["Turbo-Frame"] = turboFrameTarget;
26492649
}
2650-
if (link.hasAttribute("data-turbo-stream")) {
2651-
request.acceptResponseType(StreamMessage.contentType);
2652-
}
26532650
}
26542651
requestSucceededWithResponse() {}
26552652
requestStarted(fetchRequest) {}
@@ -2662,41 +2659,46 @@ class LinkPrefetchObserver {
26622659
}
26632660
#isPrefetchable(link) {
26642661
const href = link.getAttribute("href");
2665-
if (!href || href.startsWith("#") || link.getAttribute("data-turbo") === "false" || link.getAttribute("data-turbo-prefetch") === "false") {
2666-
return false;
2667-
}
2668-
const event = dispatch("turbo:before-prefetch", {
2669-
target: link,
2670-
cancelable: true
2671-
});
2672-
if (event.defaultPrevented) {
2673-
return false;
2674-
}
2675-
if (link.origin !== document.location.origin) {
2676-
return false;
2677-
}
2678-
if (![ "http:", "https:" ].includes(link.protocol)) {
2679-
return false;
2680-
}
2681-
if (link.pathname + link.search === document.location.pathname + document.location.search) {
2682-
return false;
2683-
}
2684-
const turboMethod = link.getAttribute("data-turbo-method");
2685-
if (turboMethod && turboMethod !== "get") {
2686-
return false;
2687-
}
2688-
if (targetsIframe(link)) {
2689-
return false;
2690-
}
2691-
const turboPrefetchParent = findClosestRecursively(link, "[data-turbo-prefetch]");
2692-
if (turboPrefetchParent && turboPrefetchParent.getAttribute("data-turbo-prefetch") === "false") {
2693-
return false;
2694-
}
2662+
if (!href) return false;
2663+
if (unfetchableLink(link)) return false;
2664+
if (linkToTheSamePage(link)) return false;
2665+
if (linkOptsOut(link)) return false;
2666+
if (nonSafeLink(link)) return false;
2667+
if (eventPrevented(link)) return false;
26952668
return true;
26962669
}
26972670
}
26982671

2699-
const targetsIframe = link => !doesNotTargetIFrame(link);
2672+
const unfetchableLink = link => link.origin !== document.location.origin || ![ "http:", "https:" ].includes(link.protocol) || link.hasAttribute("target");
2673+
2674+
const linkToTheSamePage = link => link.pathname + link.search === document.location.pathname + document.location.search || link.href.startsWith("#");
2675+
2676+
const linkOptsOut = link => {
2677+
if (link.getAttribute("data-turbo-prefetch") === "false") return true;
2678+
if (link.getAttribute("data-turbo") === "false") return true;
2679+
const turboPrefetchParent = findClosestRecursively(link, "[data-turbo-prefetch]");
2680+
if (turboPrefetchParent && turboPrefetchParent.getAttribute("data-turbo-prefetch") === "false") return true;
2681+
return false;
2682+
};
2683+
2684+
const nonSafeLink = link => {
2685+
const turboMethod = link.getAttribute("data-turbo-method");
2686+
if (turboMethod && turboMethod.toLowerCase() !== "get") return true;
2687+
if (isUJS(link)) return true;
2688+
if (link.hasAttribute("data-turbo-confirm")) return true;
2689+
if (link.hasAttribute("data-turbo-stream")) return true;
2690+
return false;
2691+
};
2692+
2693+
const isUJS = link => link.hasAttribute("data-remote") || link.hasAttribute("data-behavior") || link.hasAttribute("data-confirm") || link.hasAttribute("data-method");
2694+
2695+
const eventPrevented = link => {
2696+
const event = dispatch("turbo:before-prefetch", {
2697+
target: link,
2698+
cancelable: true
2699+
});
2700+
return event.defaultPrevented;
2701+
};
27002702

27012703
class Navigator {
27022704
constructor(delegate) {

app/assets/javascripts/turbo.min.js

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/assets/javascripts/turbo.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hotwired/turbo-rails",
3-
"version": "8.0.1",
3+
"version": "8.0.2",
44
"description": "The speed of a single-page web application without having to write any JavaScript",
55
"module": "app/javascript/turbo/index.js",
66
"main": "app/assets/javascripts/turbo.js",
@@ -13,7 +13,7 @@
1313
"release": "npm publish && git commit -am \"$npm_package_name v$npm_package_version\" && git push"
1414
},
1515
"dependencies": {
16-
"@hotwired/turbo": "^8.0.1",
16+
"@hotwired/turbo": "^8.0.2",
1717
"@rails/actioncable": "^7.0"
1818
},
1919
"devDependencies": {

yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
chalk "^2.4.2"
2525
js-tokens "^4.0.0"
2626

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

3232
"@jridgewell/gen-mapping@^0.3.0":
3333
version "0.3.3"

0 commit comments

Comments
 (0)