@@ -85,14 +85,16 @@ export function create_fetch(app) {
85
85
} ;
86
86
}
87
87
88
- window . fetch = async ( input , init ) => {
89
- const original_request = normalize_fetch_input ( input , init ) ;
90
-
91
- return app . hooks . handleFetch ( {
92
- request : original_request ,
93
- fetch : runtime_fetch
94
- } ) ;
95
- } ;
88
+ if ( BROWSER ) {
89
+ window . fetch = async ( input , init ) => {
90
+ const original_request = normalize_fetch_input ( input , init ) ;
91
+
92
+ return app . hooks . handleFetch ( {
93
+ request : original_request ,
94
+ fetch : runtime_fetch
95
+ } ) ;
96
+ } ;
97
+ }
96
98
}
97
99
98
100
const cache = new Map ( ) ;
@@ -172,7 +174,7 @@ export function dev_fetch(resource, opts) {
172
174
* @param {RequestInit } [opts]
173
175
*/
174
176
function build_selector ( resource , opts ) {
175
- const url = JSON . stringify ( resource instanceof Request ? resource . url : resource ) ;
177
+ const url = get_selector_url ( resource ) ;
176
178
177
179
let selector = `script[data-sveltekit-fetched][data-url=${ url } ]` ;
178
180
@@ -194,6 +196,20 @@ function build_selector(resource, opts) {
194
196
return selector ;
195
197
}
196
198
199
+ /**
200
+ * Build the cache url for a given request
201
+ * @param {URL | RequestInfo } resource
202
+ */
203
+ function get_selector_url ( resource ) {
204
+ if ( resource instanceof Request ) {
205
+ resource = resource . url . startsWith ( location . origin )
206
+ ? resource . url . slice ( location . origin . length )
207
+ : resource . url ;
208
+ }
209
+
210
+ return JSON . stringify ( resource ) ;
211
+ }
212
+
197
213
/**
198
214
* @param {RequestInfo | URL } info
199
215
* @param {RequestInit | undefined } init
@@ -204,5 +220,5 @@ function normalize_fetch_input(info, init) {
204
220
return info ;
205
221
}
206
222
207
- return new Request ( typeof info === 'string' ? new URL ( info ) : info , init ) ;
223
+ return new Request ( typeof info === 'string' ? new URL ( info , location . href ) : info , init ) ;
208
224
}
0 commit comments