-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: make sure promises from fetch handle errors (#11228)
Ensures that people using `fetch` directly in their load functions don't run into uncaught promise errors with streaming. Also adds some docs for this case. related to #9785
- Loading branch information
1 parent
f9b5c1f
commit 15422d2
Showing
8 changed files
with
91 additions
and
3 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: make sure promises from fetch handle errors |
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
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
1 change: 1 addition & 0 deletions
1
packages/kit/test/apps/basics/src/routes/streaming/+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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
<a href="/streaming/universal">Universal</a> | ||
<a href="/streaming/server">Server</a> | ||
<a href="/streaming/server-error">Server Error</a> |
15 changes: 15 additions & 0 deletions
15
packages/kit/test/apps/basics/src/routes/streaming/server-error/+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,15 @@ | ||
// Tests the case where a lazy promise is rejected before the rendering started | ||
export async function load({ fetch }) { | ||
const eager = new Promise((resolve) => { | ||
setTimeout(() => { | ||
resolve('eager'); | ||
}, 100); | ||
}); | ||
|
||
return { | ||
eager: await eager, | ||
lazy: { | ||
fail: fetch('http://localhost:1337/') | ||
} | ||
}; | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/kit/test/apps/basics/src/routes/streaming/server-error/+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,12 @@ | ||
<script> | ||
/** @type {import('./$types').PageData} */ | ||
export let data; | ||
</script> | ||
|
||
<p class="eager">{data.eager}</p> | ||
|
||
{#await data.lazy.fail} | ||
<p class="loadingfail">loading</p> | ||
{:catch} | ||
<p class="fail">fail</p> | ||
{/await} |
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