@@ -73,32 +73,40 @@ export function usePrefetch() {
73
73
} )
74
74
75
75
rIC ( ( ) => {
76
- document . querySelectorAll < HTMLAnchorElement > ( '#app a' ) . forEach ( ( link ) => {
77
- const { target, hostname, pathname } = link
78
- const extMatch = pathname . match ( / \. \w + $ / )
79
- if ( extMatch && extMatch [ 0 ] !== '.html' ) {
80
- return
81
- }
76
+ document
77
+ . querySelectorAll < HTMLAnchorElement | SVGAElement > ( '#app a' )
78
+ . forEach ( ( link ) => {
79
+ const { target } = link
80
+ const { hostname, pathname } = new URL (
81
+ link . href instanceof SVGAnimatedString
82
+ ? link . href . animVal
83
+ : link . href ,
84
+ link . baseURI
85
+ )
86
+ const extMatch = pathname . match ( / \. \w + $ / )
87
+ if ( extMatch && extMatch [ 0 ] !== '.html' ) {
88
+ return
89
+ }
82
90
83
- if (
84
- // only prefetch same tab navigation, since a new tab will load
85
- // the lean js chunk instead.
86
- target !== `_blank` &&
87
- // only prefetch inbound links
88
- hostname === location . hostname
89
- ) {
90
- if ( pathname !== location . pathname ) {
91
- observer ! . observe ( link )
92
- } else {
93
- // No need to prefetch chunk for the current page, but also mark
94
- // it as already fetched. This is because the initial page uses its
95
- // lean chunk, and if we don't mark it, navigation to another page
96
- // with a link back to the first page will fetch its full chunk
97
- // which isn't needed.
98
- hasFetched . add ( pathname )
91
+ if (
92
+ // only prefetch same tab navigation, since a new tab will load
93
+ // the lean js chunk instead.
94
+ target !== `_blank` &&
95
+ // only prefetch inbound links
96
+ hostname === location . hostname
97
+ ) {
98
+ if ( pathname !== location . pathname ) {
99
+ observer ! . observe ( link )
100
+ } else {
101
+ // No need to prefetch chunk for the current page, but also mark
102
+ // it as already fetched. This is because the initial page uses its
103
+ // lean chunk, and if we don't mark it, navigation to another page
104
+ // with a link back to the first page will fetch its full chunk
105
+ // which isn't needed.
106
+ hasFetched . add ( pathname )
107
+ }
99
108
}
100
- }
101
- } )
109
+ } )
102
110
} )
103
111
}
104
112
0 commit comments