1
1
/*!
2
- Turbo 8.0.1
2
+ Turbo 8.0.2
3
3
Copyright © 2024 37signals LLC
4
4
*/
5
5
( function ( prototype ) {
@@ -2647,9 +2647,6 @@ class LinkPrefetchObserver {
2647
2647
if ( turboFrameTarget && turboFrameTarget !== "_top" ) {
2648
2648
request . headers [ "Turbo-Frame" ] = turboFrameTarget ;
2649
2649
}
2650
- if ( link . hasAttribute ( "data-turbo-stream" ) ) {
2651
- request . acceptResponseType ( StreamMessage . contentType ) ;
2652
- }
2653
2650
}
2654
2651
requestSucceededWithResponse ( ) { }
2655
2652
requestStarted ( fetchRequest ) { }
@@ -2662,41 +2659,46 @@ class LinkPrefetchObserver {
2662
2659
}
2663
2660
#isPrefetchable( link ) {
2664
2661
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 ;
2695
2668
return true ;
2696
2669
}
2697
2670
}
2698
2671
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
+ } ;
2700
2702
2701
2703
class Navigator {
2702
2704
constructor ( delegate ) {
0 commit comments