Skip to content

Commit 22efe0f

Browse files
Rich-Harrismrkishi
andauthored
use free variable for native fetch (#5049)
* use free variable for native fetch * Update packages/kit/src/runtime/client/client.js Co-authored-by: Maurício Kishi <[email protected]> * Update packages/kit/src/runtime/client/client.js Co-authored-by: Maurício Kishi <[email protected]> * Update packages/kit/src/runtime/client/client.js Co-authored-by: Maurício Kishi <[email protected]> * lint errors, might as well rename in fetcher Co-authored-by: Maurício Kishi <[email protected]> Co-authored-by: mrkishi <[email protected]>
1 parent 21ee694 commit 22efe0f

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

packages/kit/src/runtime/client/client.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
notifiable_store,
1212
scroll_state
1313
} from './utils.js';
14-
import * as fetcher from './fetcher.js';
14+
import { lock_fetch, unlock_fetch, initial_fetch, native_fetch } from './fetcher.js';
1515
import { parse } from './parse.js';
1616

1717
import Root from '__GENERATED__/root.svelte';
@@ -594,7 +594,7 @@ export function create_client({ target, session, base, trailing_slash }) {
594594
add_dependency(normalized);
595595

596596
// prerendered pages may be served from any origin, so `initial_fetch` urls shouldn't be normalized
597-
return started ? fetcher.native(normalized, init) : fetcher.initial(requested, init);
597+
return started ? native_fetch(normalized, init) : initial_fetch(requested, init);
598598
},
599599
status: status ?? null,
600600
error: error ?? null
@@ -613,10 +613,10 @@ export function create_client({ target, session, base, trailing_slash }) {
613613

614614
if (import.meta.env.DEV) {
615615
try {
616-
fetcher.increment();
616+
lock_fetch();
617617
loaded = await module.load.call(null, load_input);
618618
} finally {
619-
fetcher.decrement();
619+
unlock_fetch();
620620
}
621621
} else {
622622
loaded = await module.load.call(null, load_input);
@@ -704,7 +704,7 @@ export function create_client({ target, session, base, trailing_slash }) {
704704
const is_shadow_page = has_shadow && i === a.length - 1;
705705

706706
if (is_shadow_page) {
707-
const res = await fetcher.native(
707+
const res = await native_fetch(
708708
`${url.pathname}${url.pathname.endsWith('/') ? '' : '/'}__data.json${url.search}`,
709709
{
710710
headers: {

packages/kit/src/runtime/client/fetcher.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import { hash } from '../hash.js';
22

33
let loading = 0;
44

5-
export const native = window.fetch;
5+
export const native_fetch = window.fetch;
66

7-
export function increment() {
7+
export function lock_fetch() {
88
loading += 1;
99
}
1010

11-
export function decrement() {
11+
export function unlock_fetch() {
1212
loading -= 1;
1313
}
1414

@@ -32,15 +32,16 @@ if (import.meta.env.DEV) {
3232
`Loading ${url} using \`window.fetch\`. For best results, use the \`fetch\` that is passed to your \`load\` function: https://kit.svelte.dev/docs/loading#input-fetch`
3333
);
3434
}
35-
return native(input, init);
35+
36+
return native_fetch(input, init);
3637
};
3738
}
3839

3940
/**
4041
* @param {RequestInfo} resource
4142
* @param {RequestInit} [opts]
4243
*/
43-
export function initial(resource, opts) {
44+
export function initial_fetch(resource, opts) {
4445
const url = JSON.stringify(typeof resource === 'string' ? resource : resource.url);
4546

4647
let selector = `script[sveltekit\\:data-type="data"][sveltekit\\:data-url=${url}]`;
@@ -55,5 +56,5 @@ export function initial(resource, opts) {
5556
return Promise.resolve(new Response(body, init));
5657
}
5758

58-
return native(resource, opts);
59+
return native_fetch(resource, opts);
5960
}

0 commit comments

Comments
 (0)