-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use
window.fetch
for server load fetch requests (#13315)
This PR ensures that this server-load data request is also patchable by basically using the same mechanism introduced in #10009
- Loading branch information
Showing
8 changed files
with
62 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@sveltejs/kit': patch | ||
--- | ||
|
||
fix: use current `window.fetch` for server load fetch requests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...kit/test/apps/basics/src/routes/load/window-fetch/patching-server-load-ii/+page.server.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export async function load() { | ||
return { msg: 'server load data' }; | ||
} |
10 changes: 10 additions & 0 deletions
10
...es/kit/test/apps/basics/src/routes/load/window-fetch/patching-server-load-ii/+page.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<script> | ||
export let data; | ||
</script> | ||
|
||
<p> | ||
This page makes a fetch request to the server to get the data from the server load function when | ||
users navigate to it. | ||
</p> | ||
|
||
<h1>{data.msg}</h1> |
3 changes: 3 additions & 0 deletions
3
...es/kit/test/apps/basics/src/routes/load/window-fetch/patching-server-load/+page.server.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export async function load() { | ||
return { msg: 'server load data' }; | ||
} |
18 changes: 18 additions & 0 deletions
18
packages/kit/test/apps/basics/src/routes/load/window-fetch/patching-server-load/+page.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<script> | ||
import { browser } from '$app/environment'; | ||
if (browser) { | ||
const original_fetch = window.fetch; | ||
window.fetch = (input, init) => { | ||
console.log('Called a patched window.fetch for server load request'); | ||
return original_fetch(input, init); | ||
}; | ||
} | ||
</script> | ||
|
||
<p> | ||
The sole purpose of this page is to apply a `window.fetch` patch before navigating to the next | ||
page. Click the link below to navigate to the next page with a server load function. | ||
</p> | ||
|
||
<a href="./patching-server-load-ii">Go To Page with Server Load</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters