@hotwired/turbo 8.0.0 → 8.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Turbo 8.0.0
2
+ Turbo 8.0.2
3
3
  Copyright © 2024 37signals LLC
4
4
  */
5
5
  /**
@@ -2417,11 +2417,11 @@ class Visit {
2417
2417
  complete() {
2418
2418
  if (this.state == VisitState.started) {
2419
2419
  this.recordTimingMetric(TimingMetric.visitEnd);
2420
+ this.adapter.visitCompleted(this);
2420
2421
  this.state = VisitState.completed;
2421
2422
  this.followRedirect();
2422
2423
 
2423
2424
  if (!this.followedRedirect) {
2424
- this.adapter.visitCompleted(this);
2425
2425
  this.delegate.visitCompleted(this);
2426
2426
  }
2427
2427
  }
@@ -3191,10 +3191,6 @@ class LinkPrefetchObserver {
3191
3191
  if (turboFrameTarget && turboFrameTarget !== "_top") {
3192
3192
  request.headers["Turbo-Frame"] = turboFrameTarget;
3193
3193
  }
3194
-
3195
- if (link.hasAttribute("data-turbo-stream")) {
3196
- request.acceptResponseType(StreamMessage.contentType);
3197
- }
3198
3194
  }
3199
3195
 
3200
3196
  // Fetch request interface
@@ -3218,52 +3214,54 @@ class LinkPrefetchObserver {
3218
3214
  #isPrefetchable(link) {
3219
3215
  const href = link.getAttribute("href");
3220
3216
 
3221
- if (!href || href.startsWith("#") || link.getAttribute("data-turbo") === "false" || link.getAttribute("data-turbo-prefetch") === "false") {
3222
- return false
3223
- }
3217
+ if (!href) return false
3224
3218
 
3225
- const event = dispatch("turbo:before-prefetch", {
3226
- target: link,
3227
- cancelable: true
3228
- });
3219
+ if (unfetchableLink(link)) return false
3220
+ if (linkToTheSamePage(link)) return false
3221
+ if (linkOptsOut(link)) return false
3222
+ if (nonSafeLink(link)) return false
3223
+ if (eventPrevented(link)) return false
3229
3224
 
3230
- if (event.defaultPrevented) {
3231
- return false
3232
- }
3225
+ return true
3226
+ }
3227
+ }
3233
3228
 
3234
- if (link.origin !== document.location.origin) {
3235
- return false
3236
- }
3229
+ const unfetchableLink = (link) => {
3230
+ return link.origin !== document.location.origin || !["http:", "https:"].includes(link.protocol) || link.hasAttribute("target")
3231
+ };
3237
3232
 
3238
- if (!["http:", "https:"].includes(link.protocol)) {
3239
- return false
3240
- }
3233
+ const linkToTheSamePage = (link) => {
3234
+ return (link.pathname + link.search === document.location.pathname + document.location.search) || link.href.startsWith("#")
3235
+ };
3241
3236
 
3242
- if (link.pathname + link.search === document.location.pathname + document.location.search) {
3243
- return false
3244
- }
3237
+ const linkOptsOut = (link) => {
3238
+ if (link.getAttribute("data-turbo-prefetch") === "false") return true
3239
+ if (link.getAttribute("data-turbo") === "false") return true
3245
3240
 
3246
- const turboMethod = link.getAttribute("data-turbo-method");
3247
- if (turboMethod && turboMethod !== "get") {
3248
- return false
3249
- }
3241
+ const turboPrefetchParent = findClosestRecursively(link, "[data-turbo-prefetch]");
3242
+ if (turboPrefetchParent && turboPrefetchParent.getAttribute("data-turbo-prefetch") === "false") return true
3250
3243
 
3251
- if (targetsIframe(link)) {
3252
- return false
3253
- }
3244
+ return false
3245
+ };
3254
3246
 
3255
- const turboPrefetchParent = findClosestRecursively(link, "[data-turbo-prefetch]");
3247
+ const nonSafeLink = (link) => {
3248
+ const turboMethod = link.getAttribute("data-turbo-method");
3249
+ if (turboMethod && turboMethod.toLowerCase() !== "get") return true
3256
3250
 
3257
- if (turboPrefetchParent && turboPrefetchParent.getAttribute("data-turbo-prefetch") === "false") {
3258
- return false
3259
- }
3251
+ if (isUJS(link)) return true
3252
+ if (link.hasAttribute("data-turbo-confirm")) return true
3253
+ if (link.hasAttribute("data-turbo-stream")) return true
3260
3254
 
3261
- return true
3262
- }
3263
- }
3255
+ return false
3256
+ };
3257
+
3258
+ const isUJS = (link) => {
3259
+ return link.hasAttribute("data-remote") || link.hasAttribute("data-behavior") || link.hasAttribute("data-confirm") || link.hasAttribute("data-method")
3260
+ };
3264
3261
 
3265
- const targetsIframe = (link) => {
3266
- return !doesNotTargetIFrame(link)
3262
+ const eventPrevented = (link) => {
3263
+ const event = dispatch("turbo:before-prefetch", { target: link, cancelable: true });
3264
+ return event.defaultPrevented
3267
3265
  };
3268
3266
 
3269
3267
  class Navigator {
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Turbo 8.0.0
2
+ Turbo 8.0.2
3
3
  Copyright © 2024 37signals LLC
4
4
  */
5
5
  (function (global, factory) {
@@ -2423,11 +2423,11 @@ Copyright © 2024 37signals LLC
2423
2423
  complete() {
2424
2424
  if (this.state == VisitState.started) {
2425
2425
  this.recordTimingMetric(TimingMetric.visitEnd);
2426
+ this.adapter.visitCompleted(this);
2426
2427
  this.state = VisitState.completed;
2427
2428
  this.followRedirect();
2428
2429
 
2429
2430
  if (!this.followedRedirect) {
2430
- this.adapter.visitCompleted(this);
2431
2431
  this.delegate.visitCompleted(this);
2432
2432
  }
2433
2433
  }
@@ -3197,10 +3197,6 @@ Copyright © 2024 37signals LLC
3197
3197
  if (turboFrameTarget && turboFrameTarget !== "_top") {
3198
3198
  request.headers["Turbo-Frame"] = turboFrameTarget;
3199
3199
  }
3200
-
3201
- if (link.hasAttribute("data-turbo-stream")) {
3202
- request.acceptResponseType(StreamMessage.contentType);
3203
- }
3204
3200
  }
3205
3201
 
3206
3202
  // Fetch request interface
@@ -3224,52 +3220,54 @@ Copyright © 2024 37signals LLC
3224
3220
  #isPrefetchable(link) {
3225
3221
  const href = link.getAttribute("href");
3226
3222
 
3227
- if (!href || href.startsWith("#") || link.getAttribute("data-turbo") === "false" || link.getAttribute("data-turbo-prefetch") === "false") {
3228
- return false
3229
- }
3223
+ if (!href) return false
3230
3224
 
3231
- const event = dispatch("turbo:before-prefetch", {
3232
- target: link,
3233
- cancelable: true
3234
- });
3225
+ if (unfetchableLink(link)) return false
3226
+ if (linkToTheSamePage(link)) return false
3227
+ if (linkOptsOut(link)) return false
3228
+ if (nonSafeLink(link)) return false
3229
+ if (eventPrevented(link)) return false
3235
3230
 
3236
- if (event.defaultPrevented) {
3237
- return false
3238
- }
3231
+ return true
3232
+ }
3233
+ }
3239
3234
 
3240
- if (link.origin !== document.location.origin) {
3241
- return false
3242
- }
3235
+ const unfetchableLink = (link) => {
3236
+ return link.origin !== document.location.origin || !["http:", "https:"].includes(link.protocol) || link.hasAttribute("target")
3237
+ };
3243
3238
 
3244
- if (!["http:", "https:"].includes(link.protocol)) {
3245
- return false
3246
- }
3239
+ const linkToTheSamePage = (link) => {
3240
+ return (link.pathname + link.search === document.location.pathname + document.location.search) || link.href.startsWith("#")
3241
+ };
3247
3242
 
3248
- if (link.pathname + link.search === document.location.pathname + document.location.search) {
3249
- return false
3250
- }
3243
+ const linkOptsOut = (link) => {
3244
+ if (link.getAttribute("data-turbo-prefetch") === "false") return true
3245
+ if (link.getAttribute("data-turbo") === "false") return true
3251
3246
 
3252
- const turboMethod = link.getAttribute("data-turbo-method");
3253
- if (turboMethod && turboMethod !== "get") {
3254
- return false
3255
- }
3247
+ const turboPrefetchParent = findClosestRecursively(link, "[data-turbo-prefetch]");
3248
+ if (turboPrefetchParent && turboPrefetchParent.getAttribute("data-turbo-prefetch") === "false") return true
3256
3249
 
3257
- if (targetsIframe(link)) {
3258
- return false
3259
- }
3250
+ return false
3251
+ };
3260
3252
 
3261
- const turboPrefetchParent = findClosestRecursively(link, "[data-turbo-prefetch]");
3253
+ const nonSafeLink = (link) => {
3254
+ const turboMethod = link.getAttribute("data-turbo-method");
3255
+ if (turboMethod && turboMethod.toLowerCase() !== "get") return true
3262
3256
 
3263
- if (turboPrefetchParent && turboPrefetchParent.getAttribute("data-turbo-prefetch") === "false") {
3264
- return false
3265
- }
3257
+ if (isUJS(link)) return true
3258
+ if (link.hasAttribute("data-turbo-confirm")) return true
3259
+ if (link.hasAttribute("data-turbo-stream")) return true
3266
3260
 
3267
- return true
3268
- }
3269
- }
3261
+ return false
3262
+ };
3263
+
3264
+ const isUJS = (link) => {
3265
+ return link.hasAttribute("data-remote") || link.hasAttribute("data-behavior") || link.hasAttribute("data-confirm") || link.hasAttribute("data-method")
3266
+ };
3270
3267
 
3271
- const targetsIframe = (link) => {
3272
- return !doesNotTargetIFrame(link)
3268
+ const eventPrevented = (link) => {
3269
+ const event = dispatch("turbo:before-prefetch", { target: link, cancelable: true });
3270
+ return event.defaultPrevented
3273
3271
  };
3274
3272
 
3275
3273
  class Navigator {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hotwired/turbo",
3
- "version": "8.0.0",
3
+ "version": "8.0.2",
4
4
  "description": "The speed of a single-page web application without having to write any JavaScript",
5
5
  "module": "dist/turbo.es2017-esm.js",
6
6
  "main": "dist/turbo.es2017-umd.js",